From ec1862cfe68f9e0579931d12a3942c5a82f1be9d Mon Sep 17 00:00:00 2001 From: Ian Gray Date: Sun, 2 Jan 2022 21:56:32 +0000 Subject: [PATCH] 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. --- data/js/controls.js | 67 +++++++++++++++++++++++++++++------------ data/js/controls.min.js | 50 +++++++++++++++++------------- src/ESPUI.cpp | 20 ++++++++++++ src/ESPUI.h | 5 +++ src/dataControlsJS.h | 52 ++++++++++++++++++-------------- 5 files changed, 132 insertions(+), 62 deletions(-) diff --git a/data/js/controls.js b/data/js/controls.js index 728ed7b..f8a8101 100644 --- a/data/js/controls.js +++ b/data/js/controls.js @@ -233,6 +233,9 @@ function start() { 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: // Clear current elements @@ -278,9 +281,9 @@ function start() { } if (data.visible) { parent.append( - "
" + "
" + @@ -288,7 +291,7 @@ function start() { "

" + "" + + "' " + elementStyle + " class='label label-wrap'>" + data.value + "" + "
" @@ -307,7 +310,7 @@ function start() { parent.append( "
" + "
" + @@ -315,7 +318,7 @@ function start() { "

" + "