s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266
https://valencia.lbsfilm.at/midterm-presentation/
Other
902 stars 170 forks source link

Labels missing with grouped items #202

Open bubshowlett opened 1 year ago

bubshowlett commented 1 year ago

When grouping elements of different types together the labels for each element are not shown.

The following shows each element ungroup and each has a label

single elements

The following shows the same elements grouped together and the labels have gone

grouped elements

Is there away to keep the labels when grouping different elements?

iangray001 commented 1 year ago

The completeExample.cpp has a few example of using ESPUI labels and inline styles to label grouped controls. It's not perfect but it is the most flexible approach.

dewenni commented 1 year ago

With the possibility of inline styles you can create different and flexible groups.

examples:

image image

the key is to use the ESPUI.setElementStyle(value_id, LABLE_STYLE_VALUE); and split the 100% width for the different items. For example 60% for the Label, 30% for the value and 10% for the unit.

#define LABLE_STYLE_CLEAR "background-color: unset; width: 60%; text-align: left;"

#define LABLE_STYLE_VALUE "width: 30%;"

#define LABLE_STYLE_UNIT "background-color: unset; width: 10%; text-align: left;"

BuzzerBoy commented 1 year ago

@dewenni Do you have a code example for these graphic examples you posted? I learn by reverse engineering :)

dewenni commented 1 year ago

@BuzzerBoy

I have written some "helper" functions for that.

// Helper function to add a new group Element
uint16_t addGroupHelper(const char * title, ControlColor color, uint16_t tab) {
   auto groupID = ESPUI.addControl(Label, title, "", color, tab);
   ESPUI.setElementStyle(groupID, LABLE_STYLE_GROUP);
   return groupID;
}
// Helper function to add a new Element to a existing group
uint16_t addGroupValueHelper(const char * title, String value, String unit, uint16_t group) {
  ESPUI.setElementStyle(ESPUI.addControl(Label, "", title, None, group), LABLE_STYLE_CLEAR);
  uint16_t value_id = ESPUI.addControl(Label, "", value, None, group);
  ESPUI.setElementStyle(value_id, LABLE_STYLE_VALUE);
  ESPUI.setElementStyle(ESPUI.addControl(Label, "", unit, None, group), LABLE_STYLE_UNIT);
  return value_id;
}

and here the example for the WiFi Info group from the picture above

  auto wiFiGroup = addGroupHelper("WiFi-Info", Dark, id.tab.system);
  id.sys.wifiIP      = addGroupValueHelper(webText.WIFI_IP[config.lang], "--", "", wiFiGroup);
  id.sys.wifiSignal  = addGroupValueHelper("WiFi-Signal", "--", "%", wiFiGroup);
  id.sys.wifiRssi    = addGroupValueHelper("WiFi-Rssi", "--", "dbm", wiFiGroup);

the full example can be found here: https://github.com/dewenni/ESP_Buderus_KM271/blob/74b06222d649d1ebe006857de790c6ff3e2db80f/src/webUI.cpp

BuzzerBoy commented 1 year ago

Ty. That helped a lot!