#include "ESPUI.h" static uint16_t idCounter = 0; static const String ControlError = "*** ESPUI ERROR: Could not transfer control ***"; Control::Control(ControlType type, const char* label, void (*callback)(Control*, int, void*), void* UserData, const String& value, ControlColor color, bool visible, uint16_t parentControl) : type(type), label(label), callback(nullptr), extendedCallback(callback), user(UserData), value(value), color(color), visible(visible), wide(false), vertical(false), enabled(true), parentControl(parentControl), next(nullptr) { id = ++idCounter; } Control::Control(const Control& Control) : type(Control.type), id(Control.id), label(Control.label), callback(Control.callback), extendedCallback(Control.extendedCallback), user(Control.user), value(Control.value), color(Control.color), visible(Control.visible), parentControl(Control.parentControl), next(Control.next) { } void Control::SendCallback(int type) { if(callback) { callback(this, type); } if (extendedCallback) { extendedCallback(this, type, user); } } void Control::DeleteControl() { ControlSyncState = ControlSyncState_t::deleted; extendedCallback = nullptr; callback = nullptr; } void Control::MarshalControl(JsonObject & item, bool refresh) { item[F("id")] = id; ControlType TempType = (ControlType::Password == type) ? ControlType::Text : type; if(refresh) { item[F("type")] = uint32_t(TempType) + uint32_t(ControlType::UpdateOffset); } else { item[F("type")] = uint32_t(TempType); } item[F("label")] = label; item[F ("value")] = (ControlType::Password == type) ? F ("--------") : value; item[F("visible")] = visible; item[F("color")] = (int)color; item[F("enabled")] = enabled; if (!panelStyle.isEmpty()) {item[F("panelStyle")] = panelStyle;} if (!elementStyle.isEmpty()) {item[F("elementStyle")] = elementStyle;} if (!inputType.isEmpty()) {item[F("inputType")] = inputType;} if (wide == true) {item[F("wide")] = true;} if (vertical == true) {item[F("vertical")] = true;} if (parentControl != Control::noParent) { item[F("parentControl")] = String(parentControl); } // special case for selects: to preselect an option, you have to add // "selected" to