mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-22 04:00:55 +00:00
Support for dynamic custom inline styling.
Adds two functions in ESPUI.h: setPanelStyle() setElementStyle() These allow for custom inline CSS styles to be applied to the panel and to the specific UI element repectively. For example: ``` char stylecol1[30] sprintf(stylecol1, "background-color: #%06X;", (unsigned int) random(0x0, 0xFFFFFF)); ESPUI.setPanelStyle(switch1, stylecol1); ``` This will set the panel of the given control to a random hex colour. This is supported by both the initial UI message, and by control update messages, so you can change these styles dynamically in response to other events. setElementStyle() is not perfect. Because CSS inline styles can only style one specific DOM element, for controls made up of multiple elements (like the "pad") this is limited. I have tried to make an appropriate choice for each supported control.
This commit is contained in:
parent
06460fcc4d
commit
232ca3ead4
65
data/js/controls.js
vendored
65
data/js/controls.js
vendored
@ -233,6 +233,9 @@ function start() {
|
|||||||
var e = document.body;
|
var e = document.body;
|
||||||
var center = "";
|
var center = "";
|
||||||
|
|
||||||
|
panelStyle = data.hasOwnProperty('panelStyle') ? " style='" + data.panelStyle + "'" : "";
|
||||||
|
elementStyle = data.hasOwnProperty('elementStyle') ? " style='" + data.elementStyle + "'" : "";
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case UI_INITIAL_GUI:
|
case UI_INITIAL_GUI:
|
||||||
// Clear current elements
|
// Clear current elements
|
||||||
@ -280,7 +283,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -288,7 +291,7 @@ function start() {
|
|||||||
"</h5><hr/>" +
|
"</h5><hr/>" +
|
||||||
"<span id='l" +
|
"<span id='l" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='label label-wrap'>" +
|
"' " + elementStyle + " class='label label-wrap'>" +
|
||||||
data.value +
|
data.value +
|
||||||
"</span>" +
|
"</span>" +
|
||||||
"</div>"
|
"</div>"
|
||||||
@ -307,7 +310,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='one columns card tcenter " +
|
"' " + panelStyle + " class='one columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -315,7 +318,7 @@ function start() {
|
|||||||
"</h5><hr/>" +
|
"</h5><hr/>" +
|
||||||
"<button id='btn" +
|
"<button id='btn" +
|
||||||
data.id +
|
data.id +
|
||||||
"' " +
|
"' " + elementStyle + " " +
|
||||||
"onmousedown='buttonclick(" +
|
"onmousedown='buttonclick(" +
|
||||||
data.id +
|
data.id +
|
||||||
", true)' " +
|
", true)' " +
|
||||||
@ -349,7 +352,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='one columns card tcenter " +
|
"' " + panelStyle + " class='one columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -357,7 +360,7 @@ function start() {
|
|||||||
"</h5><hr/>" +
|
"</h5><hr/>" +
|
||||||
"<label id='sl" +
|
"<label id='sl" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='switch " +
|
"' " + elementStyle + " class='switch " +
|
||||||
(data.value == "1" ? "checked" : "") +
|
(data.value == "1" ? "checked" : "") +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<div class='in'><input type='checkbox' id='s" +
|
"<div class='in'><input type='checkbox' id='s" +
|
||||||
@ -386,7 +389,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -501,7 +504,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter card-slider " +
|
"' " + panelStyle + " class='two columns card tcenter card-slider " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -512,7 +515,7 @@ function start() {
|
|||||||
data.id +
|
data.id +
|
||||||
"' type='range' min='0' max='100' value='" +
|
"' type='range' min='0' max='100' value='" +
|
||||||
data.value +
|
data.value +
|
||||||
"' class='range-slider__range'>" +
|
"' " + elementStyle + " class='range-slider__range'>" +
|
||||||
"<span class='range-slider__value'>" +
|
"<span class='range-slider__value'>" +
|
||||||
data.value +
|
data.value +
|
||||||
"</span>" +
|
"</span>" +
|
||||||
@ -534,13 +537,13 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
data.label +
|
data.label +
|
||||||
"</h5><hr/>" +
|
"</h5><hr/>" +
|
||||||
"<input style='color:black;' id='num" +
|
"<input style='color:black;' " + elementStyle + " id='num" +
|
||||||
data.id +
|
data.id +
|
||||||
"' type='number' value='" +
|
"' type='number' value='" +
|
||||||
data.value +
|
data.value +
|
||||||
@ -563,13 +566,13 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
data.label +
|
data.label +
|
||||||
"</h5><hr/>" +
|
"</h5><hr/>" +
|
||||||
"<input style='color:black;' id='text" +
|
"<input style='color:black;' " + elementStyle + " id='text" +
|
||||||
data.id +
|
data.id +
|
||||||
"' value='" +
|
"' value='" +
|
||||||
data.value +
|
data.value +
|
||||||
@ -615,13 +618,13 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
data.label +
|
data.label +
|
||||||
"</h5><hr/>" +
|
"</h5><hr/>" +
|
||||||
"<select style='color:black;' id='select" +
|
"<select style='color:black;' " + elementStyle + " id='select" +
|
||||||
data.id +
|
data.id +
|
||||||
"' onchange='selectchange(" +
|
"' onchange='selectchange(" +
|
||||||
data.id +
|
data.id +
|
||||||
@ -685,7 +688,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -726,7 +729,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -757,7 +760,7 @@ function start() {
|
|||||||
parent.append(
|
parent.append(
|
||||||
"<div id='id" +
|
"<div id='id" +
|
||||||
data.id +
|
data.id +
|
||||||
"' class='two columns card tcenter " +
|
"' " + panelStyle + " class='two columns card tcenter " +
|
||||||
colorClass(data.color) +
|
colorClass(data.color) +
|
||||||
"'>" +
|
"'>" +
|
||||||
"<h5>" +
|
"<h5>" +
|
||||||
@ -779,26 +782,44 @@ function start() {
|
|||||||
|
|
||||||
case UPDATE_LABEL:
|
case UPDATE_LABEL:
|
||||||
$("#l" + data.id).html(data.value);
|
$("#l" + data.id).html(data.value);
|
||||||
|
if(data.hasOwnProperty('elementStyle')) {
|
||||||
|
$("#l" + data.id).attr("style", data.elementStyle);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_SWITCHER:
|
case UPDATE_SWITCHER:
|
||||||
switcher(data.id, data.value == "0" ? 0 : 1);
|
switcher(data.id, data.value == "0" ? 0 : 1);
|
||||||
|
if(data.hasOwnProperty('elementStyle')) {
|
||||||
|
$("#sl" + data.id).attr("style", data.elementStyle);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_SLIDER:
|
case UPDATE_SLIDER:
|
||||||
slider_move($("#id" + data.id), data.value, "100", false);
|
slider_move($("#id" + data.id), data.value, "100", false);
|
||||||
|
if(data.hasOwnProperty('elementStyle')) {
|
||||||
|
$("#sl" + data.id).attr("style", data.elementStyle);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_NUMBER:
|
case UPDATE_NUMBER:
|
||||||
$("#num" + data.id).val(data.value);
|
$("#num" + data.id).val(data.value);
|
||||||
|
if(data.hasOwnProperty('elementStyle')) {
|
||||||
|
$("#num" + data.id).attr("style", data.elementStyle);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_TEXT_INPUT:
|
case UPDATE_TEXT_INPUT:
|
||||||
$("#text" + data.id).val(data.value);
|
$("#text" + data.id).val(data.value);
|
||||||
|
if(data.hasOwnProperty('elementStyle')) {
|
||||||
|
$("#text" + data.id).attr("style", data.elementStyle);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_SELECT:
|
case UPDATE_SELECT:
|
||||||
$("#select" + data.id).val(data.value);
|
$("#select" + data.id).val(data.value);
|
||||||
|
if(data.hasOwnProperty('elementStyle')) {
|
||||||
|
$("#select" + data.id).attr("style", data.elementStyle);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_BUTTON:
|
case UPDATE_BUTTON:
|
||||||
@ -807,6 +828,9 @@ function start() {
|
|||||||
break;
|
break;
|
||||||
case UPDATE_GAUGE:
|
case UPDATE_GAUGE:
|
||||||
$("#gauge" + data.id).val(data.value);
|
$("#gauge" + data.id).val(data.value);
|
||||||
|
if(data.hasOwnProperty('elementStyle')) {
|
||||||
|
$("#gauge" + data.id).attr("style", data.elementStyle);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case UPDATE_ACCEL:
|
case UPDATE_ACCEL:
|
||||||
break;
|
break;
|
||||||
@ -818,6 +842,11 @@ function start() {
|
|||||||
|
|
||||||
if (data.type >= UPDATE_OFFSET && data.type < UI_INITIAL_GUI) {
|
if (data.type >= UPDATE_OFFSET && data.type < UI_INITIAL_GUI) {
|
||||||
var element = $("#id" + data.id);
|
var element = $("#id" + data.id);
|
||||||
|
|
||||||
|
if(data.hasOwnProperty('panelStyle')) {
|
||||||
|
$("#id" + data.id).attr("style", data.panelStyle);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.type == UPDATE_SLIDER) {
|
if (data.type == UPDATE_SLIDER) {
|
||||||
element.removeClass(
|
element.removeClass(
|
||||||
"slider-turquoise slider-emerald slider-peterriver slider-wetasphalt slider-sunflower slider-carrot slider-alizarin"
|
"slider-turquoise slider-emerald slider-peterriver slider-wetasphalt slider-sunflower slider-carrot slider-alizarin"
|
||||||
|
50
data/js/controls.min.js
vendored
50
data/js/controls.min.js
vendored
@ -7,11 +7,11 @@ function restart(){$(document).add("*").off();$("#row").html("");websock.close()
|
|||||||
function conStatusError(){websockConnected=false;$("#conStatus").removeClass("color-green");$("#conStatus").addClass("color-red");$("#conStatus").html("Error / No Connection ↻");$("#conStatus").off();$("#conStatus").on({click:restart,});}
|
function conStatusError(){websockConnected=false;$("#conStatus").removeClass("color-green");$("#conStatus").addClass("color-red");$("#conStatus").html("Error / No Connection ↻");$("#conStatus").off();$("#conStatus").on({click:restart,});}
|
||||||
function handleVisibilityChange(){if(!websockConnected&&!document.hidden){restart();}}
|
function handleVisibilityChange(){if(!websockConnected&&!document.hidden){restart();}}
|
||||||
function start(){document.addEventListener("visibilitychange",handleVisibilityChange,false);if(window.location.port!=""||window.location.port!=80||window.location.port!=443){websock=new WebSocket("ws://"+window.location.hostname+":"+window.location.port+"/ws");}else{websock=new WebSocket("ws://"+window.location.hostname+"/ws");}
|
function start(){document.addEventListener("visibilitychange",handleVisibilityChange,false);if(window.location.port!=""||window.location.port!=80||window.location.port!=443){websock=new WebSocket("ws://"+window.location.hostname+":"+window.location.port+"/ws");}else{websock=new WebSocket("ws://"+window.location.hostname+"/ws");}
|
||||||
websock.onopen=function(evt){console.log("websock open");$("#conStatus").addClass("color-green");$("#conStatus").text("Connected");websockConnected=true;};websock.onclose=function(evt){console.log("websock close");conStatusError();};websock.onerror=function(evt){console.log(evt);conStatusError();};var handleEvent=function(evt){console.log(evt);var data=JSON.parse(evt.data);var e=document.body;var center="";switch(data.type){case UI_INITIAL_GUI:$("#row").html("");$("#tabsnav").html("");$("#tabscontent").html("");if(data.sliderContinuous){sliderContinuous=data.sliderContinuous;}
|
websock.onopen=function(evt){console.log("websock open");$("#conStatus").addClass("color-green");$("#conStatus").text("Connected");websockConnected=true;};websock.onclose=function(evt){console.log("websock close");conStatusError();};websock.onerror=function(evt){console.log(evt);conStatusError();};var handleEvent=function(evt){console.log(evt);var data=JSON.parse(evt.data);var e=document.body;var center="";panelStyle=data.hasOwnProperty('panelStyle')?" style='"+data.panelStyle+"'":"";elementStyle=data.hasOwnProperty('elementStyle')?" style='"+data.elementStyle+"'":"";switch(data.type){case UI_INITIAL_GUI:$("#row").html("");$("#tabsnav").html("");$("#tabscontent").html("");if(data.sliderContinuous){sliderContinuous=data.sliderContinuous;}
|
||||||
data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_EXTEND_GUI:data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_RELOAD:window.location.reload();break;case UI_TITEL:document.title=data.label;$("#mainHeader").html(data.label);break;case UI_LABEL:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_EXTEND_GUI:data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_RELOAD:window.location.reload();break;case UI_TITEL:document.title=data.label;$("#mainHeader").html(data.label);break;case UI_LABEL:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -19,14 +19,14 @@ data.label+
|
|||||||
"</h5><hr/>"+
|
"</h5><hr/>"+
|
||||||
"<span id='l"+
|
"<span id='l"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='label label-wrap'>"+
|
"' "+elementStyle+" class='label label-wrap'>"+
|
||||||
data.value+
|
data.value+
|
||||||
"</span>"+
|
"</span>"+
|
||||||
"</div>");}
|
"</div>");}
|
||||||
break;case UI_BUTTON:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_BUTTON:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='one columns card tcenter "+
|
"' "+panelStyle+" class='one columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -34,7 +34,7 @@ data.label+
|
|||||||
"</h5><hr/>"+
|
"</h5><hr/>"+
|
||||||
"<button id='btn"+
|
"<button id='btn"+
|
||||||
data.id+
|
data.id+
|
||||||
"' "+
|
"' "+elementStyle+" "+
|
||||||
"onmousedown='buttonclick("+
|
"onmousedown='buttonclick("+
|
||||||
data.id+
|
data.id+
|
||||||
", true)' "+
|
", true)' "+
|
||||||
@ -46,7 +46,7 @@ data.value+
|
|||||||
break;case UI_SWITCHER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_SWITCHER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='one columns card tcenter "+
|
"' "+panelStyle+" class='one columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -54,7 +54,7 @@ data.label+
|
|||||||
"</h5><hr/>"+
|
"</h5><hr/>"+
|
||||||
"<label id='sl"+
|
"<label id='sl"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='switch "+
|
"' "+elementStyle+" class='switch "+
|
||||||
(data.value=="1"?"checked":"")+
|
(data.value=="1"?"checked":"")+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<div class='in'><input type='checkbox' id='s"+
|
"<div class='in'><input type='checkbox' id='s"+
|
||||||
@ -69,7 +69,7 @@ data.id+
|
|||||||
break;case UI_CPAD:case UI_PAD:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_CPAD:case UI_PAD:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -118,7 +118,7 @@ data.id+
|
|||||||
break;case UI_SLIDER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_SLIDER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter card-slider "+
|
"' "+panelStyle+" class='two columns card tcenter card-slider "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -129,7 +129,7 @@ data.label+
|
|||||||
data.id+
|
data.id+
|
||||||
"' type='range' min='0' max='100' value='"+
|
"' type='range' min='0' max='100' value='"+
|
||||||
data.value+
|
data.value+
|
||||||
"' class='range-slider__range'>"+
|
"' "+elementStyle+" class='range-slider__range'>"+
|
||||||
"<span class='range-slider__value'>"+
|
"<span class='range-slider__value'>"+
|
||||||
data.value+
|
data.value+
|
||||||
"</span>"+
|
"</span>"+
|
||||||
@ -138,13 +138,13 @@ data.value+
|
|||||||
break;case UI_NUMBER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_NUMBER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
data.label+
|
data.label+
|
||||||
"</h5><hr/>"+
|
"</h5><hr/>"+
|
||||||
"<input style='color:black;' id='num"+
|
"<input style='color:black;' "+elementStyle+" id='num"+
|
||||||
data.id+
|
data.id+
|
||||||
"' type='number' value='"+
|
"' type='number' value='"+
|
||||||
data.value+
|
data.value+
|
||||||
@ -155,13 +155,13 @@ data.id+
|
|||||||
break;case UI_TEXT_INPUT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_TEXT_INPUT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
data.label+
|
data.label+
|
||||||
"</h5><hr/>"+
|
"</h5><hr/>"+
|
||||||
"<input style='color:black;' id='text"+
|
"<input style='color:black;' "+elementStyle+" id='text"+
|
||||||
data.id+
|
data.id+
|
||||||
"' value='"+
|
"' value='"+
|
||||||
data.value+
|
data.value+
|
||||||
@ -174,13 +174,13 @@ e.preventDefault();});}
|
|||||||
break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
data.label+
|
data.label+
|
||||||
"</h5><hr/>"+
|
"</h5><hr/>"+
|
||||||
"<select style='color:black;' id='select"+
|
"<select style='color:black;' "+elementStyle+" id='select"+
|
||||||
data.id+
|
data.id+
|
||||||
"' onchange='selectchange("+
|
"' onchange='selectchange("+
|
||||||
data.id+
|
data.id+
|
||||||
@ -201,7 +201,7 @@ break;case UI_STEP:if(data.parentControl){var parent=$("#id"+data.parentControl+
|
|||||||
break;case UI_GRAPH:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_GRAPH:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -218,7 +218,7 @@ data.label+
|
|||||||
break;case ADD_GRAPH_POINT:var ts=Math.round(new Date().getTime()/1000);graphData[data.id].push({x:ts,y:data.value});saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case CLEAR_GRAPH:graphData[data.id]=[];saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case UI_GAUGE:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case ADD_GRAPH_POINT:var ts=Math.round(new Date().getTime()/1000);graphData[data.id].push({x:ts,y:data.value});saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case CLEAR_GRAPH:graphData[data.id]=[];saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case UI_GAUGE:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
if(data.visible){parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -235,7 +235,7 @@ data.id+
|
|||||||
break;case UI_ACCEL:if(hasAccel)break;var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_ACCEL:if(hasAccel)break;var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
hasAccel=true;if(data.visible){parent.append("<div id='id"+
|
hasAccel=true;if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' "+panelStyle+" class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
"'>"+
|
"'>"+
|
||||||
"<h5>"+
|
"<h5>"+
|
||||||
@ -249,8 +249,16 @@ data.id+
|
|||||||
data.id+
|
data.id+
|
||||||
"'></pre>"+
|
"'></pre>"+
|
||||||
"</div>");requestOrientationPermission();}
|
"</div>");requestOrientationPermission();}
|
||||||
break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;}
|
break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);if(data.hasOwnProperty('elementStyle')){$("#l"+data.id).attr("style",data.elementStyle);}
|
||||||
if(data.type>=UPDATE_OFFSET&&data.type<UI_INITIAL_GUI){var element=$("#id"+data.id);if(data.type==UPDATE_SLIDER){element.removeClass("slider-turquoise slider-emerald slider-peterriver slider-wetasphalt slider-sunflower slider-carrot slider-alizarin");element.addClass("slider-"+colorClass(data.color));}else{element.removeClass("turquoise emerald peterriver wetasphalt sunflower carrot alizarin");element.addClass(colorClass(data.color));}}
|
break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);if(data.hasOwnProperty('elementStyle')){$("#sl"+data.id).attr("style",data.elementStyle);}
|
||||||
|
break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);if(data.hasOwnProperty('elementStyle')){$("#sl"+data.id).attr("style",data.elementStyle);}
|
||||||
|
break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);if(data.hasOwnProperty('elementStyle')){$("#num"+data.id).attr("style",data.elementStyle);}
|
||||||
|
break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);if(data.hasOwnProperty('elementStyle')){$("#text"+data.id).attr("style",data.elementStyle);}
|
||||||
|
break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);if(data.hasOwnProperty('elementStyle')){$("#select"+data.id).attr("style",data.elementStyle);}
|
||||||
|
break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);if(data.hasOwnProperty('elementStyle')){$("#gauge"+data.id).attr("style",data.elementStyle);}
|
||||||
|
break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;}
|
||||||
|
if(data.type>=UPDATE_OFFSET&&data.type<UI_INITIAL_GUI){var element=$("#id"+data.id);if(data.hasOwnProperty('panelStyle')){$("#id"+data.id).attr("style",data.panelStyle);}
|
||||||
|
if(data.type==UPDATE_SLIDER){element.removeClass("slider-turquoise slider-emerald slider-peterriver slider-wetasphalt slider-sunflower slider-carrot slider-alizarin");element.addClass("slider-"+colorClass(data.color));}else{element.removeClass("turquoise emerald peterriver wetasphalt sunflower carrot alizarin");element.addClass(colorClass(data.color));}}
|
||||||
$(".range-slider__range").each(function(){$(this)[0].value=$(this).attr("value");$(this).next().html($(this).attr("value"));});};websock.onmessage=handleEvent;}
|
$(".range-slider__range").each(function(){$(this)[0].value=$(this).attr("value");$(this).next().html($(this).attr("value"));});};websock.onmessage=handleEvent;}
|
||||||
function sliderchange(number){var val=$("#sl"+number).val();websock.send("slvalue:"+val+":"+number);}
|
function sliderchange(number){var val=$("#sl"+number).val();websock.send("slvalue:"+val+":"+number);}
|
||||||
function numberchange(number){var val=$("#num"+number).val();websock.send("nvalue:"+val+":"+number);}
|
function numberchange(number){var val=$("#num"+number).val();websock.send("nvalue:"+val+":"+number);}
|
||||||
|
@ -757,6 +757,10 @@ void ESPUIClass::updateControl(Control* control, int clientId)
|
|||||||
root["id"] = control->id;
|
root["id"] = control->id;
|
||||||
root["visible"] = control->visible;
|
root["visible"] = control->visible;
|
||||||
root["color"] = (int)control->color;
|
root["color"] = (int)control->color;
|
||||||
|
if (control->panelStyle != 0)
|
||||||
|
root["panelStyle"] = control->panelStyle;
|
||||||
|
if (control->elementStyle != 0)
|
||||||
|
root["elementStyle"] = control->elementStyle;
|
||||||
serializeJson(document, json);
|
serializeJson(document, json);
|
||||||
|
|
||||||
#if defined(DEBUG_ESPUI)
|
#if defined(DEBUG_ESPUI)
|
||||||
@ -797,6 +801,26 @@ void ESPUIClass::updateControl(Control* control, int clientId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESPUIClass::setPanelStyle(uint16_t id, String style, int clientId)
|
||||||
|
{
|
||||||
|
Control* control = getControl(id);
|
||||||
|
if (control)
|
||||||
|
{
|
||||||
|
control->panelStyle = style;
|
||||||
|
updateControl(control, clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ESPUIClass::setElementStyle(uint16_t id, String style, int clientId)
|
||||||
|
{
|
||||||
|
Control* control = getControl(id);
|
||||||
|
if (control)
|
||||||
|
{
|
||||||
|
control->elementStyle = style;
|
||||||
|
updateControl(control, clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ESPUIClass::updateControl(uint16_t id, int clientId)
|
void ESPUIClass::updateControl(uint16_t id, int clientId)
|
||||||
{
|
{
|
||||||
Control* control = getControl(id);
|
Control* control = getControl(id);
|
||||||
@ -947,7 +971,8 @@ Initially this function used to send the control element data individually.
|
|||||||
Due to a change in the ESPAsyncWebserver library this had top be changed to be
|
Due to a change in the ESPAsyncWebserver library this had top be changed to be
|
||||||
sent as one blob at the beginning. Therefore a new type is used as well
|
sent as one blob at the beginning. Therefore a new type is used as well
|
||||||
*/
|
*/
|
||||||
void ESPUIClass::jsonDom(AsyncWebSocketClient* client) {
|
void ESPUIClass::jsonDom(AsyncWebSocketClient* client)
|
||||||
|
{
|
||||||
|
|
||||||
DynamicJsonDocument document(jsonInitialDocumentSize);
|
DynamicJsonDocument document(jsonInitialDocumentSize);
|
||||||
document["type"] = (int)UI_INITIAL_GUI;
|
document["type"] = (int)UI_INITIAL_GUI;
|
||||||
@ -960,21 +985,26 @@ void ESPUIClass::jsonDom(AsyncWebSocketClient* client) {
|
|||||||
titleItem["type"] = (int)UI_TITLE;
|
titleItem["type"] = (int)UI_TITLE;
|
||||||
titleItem["label"] = ui_title;
|
titleItem["label"] = ui_title;
|
||||||
|
|
||||||
while(1) {
|
while (1)
|
||||||
|
{
|
||||||
control = prepareJSONChunk(client, control, &items);
|
control = prepareJSONChunk(client, control, &items);
|
||||||
|
|
||||||
String json;
|
String json;
|
||||||
serializeJson(document, json);
|
serializeJson(document, json);
|
||||||
#if defined(DEBUG_ESPUI)
|
#if defined(DEBUG_ESPUI)
|
||||||
if (this->verbosity >= Verbosity::VerboseJSON) {
|
if (this->verbosity >= Verbosity::VerboseJSON)
|
||||||
|
{
|
||||||
Serial.println("Sending elements --------->");
|
Serial.println("Sending elements --------->");
|
||||||
Serial.println(json);
|
Serial.println(json);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (client != nullptr) client->text(json);
|
if (client != nullptr)
|
||||||
else this->ws->textAll(json);
|
client->text(json);
|
||||||
|
else
|
||||||
|
this->ws->textAll(json);
|
||||||
|
|
||||||
if(control == nullptr) break;
|
if (control == nullptr)
|
||||||
|
break;
|
||||||
|
|
||||||
document.clear();
|
document.clear();
|
||||||
items.clear();
|
items.clear();
|
||||||
@ -983,14 +1013,15 @@ void ESPUIClass::jsonDom(AsyncWebSocketClient* client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Prepare a chunk of elements as a single JSON string. If the allowed number of elements is greater than the total
|
||||||
/* Prepare a chunk of elements as a single JSON string. If the allowed number of elements is greater than the total number
|
number this will represent the entire UI and this function will return null. If a control pointer is returned then the
|
||||||
this will represent the entire UI and this function will return null. If a control pointer is returned then the limit
|
limit was reached, the currently serialised must be sent, and then processing resumed to send the next chunk. */
|
||||||
was reached, the currently serialised must be sent, and then processing resumed to send the next chunk. */
|
Control* ESPUIClass::prepareJSONChunk(AsyncWebSocketClient* client, Control* control, JsonArray* items)
|
||||||
Control *ESPUIClass::prepareJSONChunk(AsyncWebSocketClient* client, Control* control, JsonArray *items) {
|
{
|
||||||
int elementcount = 0;
|
int elementcount = 0;
|
||||||
|
|
||||||
while (control != nullptr && elementcount < 10) {
|
while (control != nullptr && elementcount < 10)
|
||||||
|
{
|
||||||
JsonObject item = items->createNestedObject();
|
JsonObject item = items->createNestedObject();
|
||||||
|
|
||||||
item["id"] = String(control->id);
|
item["id"] = String(control->id);
|
||||||
@ -999,18 +1030,26 @@ Control *ESPUIClass::prepareJSONChunk(AsyncWebSocketClient* client, Control* con
|
|||||||
item["value"] = String(control->value);
|
item["value"] = String(control->value);
|
||||||
item["color"] = (int)control->color;
|
item["color"] = (int)control->color;
|
||||||
item["visible"] = (int)control->visible;
|
item["visible"] = (int)control->visible;
|
||||||
|
if (control->panelStyle != 0)
|
||||||
|
item["panelStyle"] = String(control->panelStyle);
|
||||||
|
if (control->elementStyle != 0)
|
||||||
|
item["elementStyle"] = String(control->elementStyle);
|
||||||
|
|
||||||
if (control->parentControl != Control::noParent) {
|
if (control->parentControl != Control::noParent)
|
||||||
|
{
|
||||||
item["parentControl"] = String(control->parentControl);
|
item["parentControl"] = String(control->parentControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// special case for selects: to preselect an option, you have to add
|
// special case for selects: to preselect an option, you have to add
|
||||||
// "selected" to <option>
|
// "selected" to <option>
|
||||||
if (control->type == ControlType::Option) {
|
if (control->type == ControlType::Option)
|
||||||
if (ESPUI.getControl(control->parentControl)->value == control->value) {
|
{
|
||||||
|
if (ESPUI.getControl(control->parentControl)->value == control->value)
|
||||||
|
{
|
||||||
item["selected"] = "selected";
|
item["selected"] = "selected";
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
item["selected"] = "";
|
item["selected"] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,8 @@ public:
|
|||||||
ControlColor color;
|
ControlColor color;
|
||||||
bool visible;
|
bool visible;
|
||||||
uint16_t parentControl;
|
uint16_t parentControl;
|
||||||
|
String panelStyle;
|
||||||
|
String elementStyle;
|
||||||
Control* next;
|
Control* next;
|
||||||
|
|
||||||
static constexpr uint16_t noParent = 0xffff;
|
static constexpr uint16_t noParent = 0xffff;
|
||||||
@ -281,6 +283,9 @@ public:
|
|||||||
void clearGraph(uint16_t id, int clientId = -1);
|
void clearGraph(uint16_t id, int clientId = -1);
|
||||||
void addGraphPoint(uint16_t id, int nValue, int clientId = -1);
|
void addGraphPoint(uint16_t id, int nValue, int clientId = -1);
|
||||||
|
|
||||||
|
void setPanelStyle(uint16_t id, String style, int clientId = -1);
|
||||||
|
void setElementStyle(uint16_t id, String style, int clientId = -1);
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
|
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
|
||||||
Control* controls = nullptr;
|
Control* controls = nullptr;
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user