1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-22 14:20:53 +00:00

Made Type and ID private and added accessors for them.

This commit is contained in:
Martin 2024-07-18 11:45:29 -04:00
parent bddcde4e57
commit 83104e9e1e

View File

@ -1,11 +1,11 @@
#include "ESPUI.h" #include "ESPUI.h"
static uint16_t idCounter = 0;
static const String ControlError = "*** ESPUI ERROR: Could not transfer control ***"; static const String ControlError = "*** ESPUI ERROR: Could not transfer control ***";
Control::Control(Control::Type type, const char* label, std::function<void(Control*, int)> callback, Control::Control(Control::ControlId_t id, Control::Type type, const char* label, std::function<void(Control*, int)> callback,
const String& value, Control::Color color, bool visible, uint16_t parentControl) const String& value, Control::Color color, bool visible, ControlId_t parentControl)
: type(type), : id(id),
type(type),
label(label), label(label),
callback(callback), callback(callback),
value(value), value(value),
@ -14,24 +14,21 @@ Control::Control(Control::Type type, const char* label, std::function<void(Contr
wide(false), wide(false),
vertical(false), vertical(false),
enabled(true), enabled(true),
parentControl(parentControl), parentControl(parentControl)
next(nullptr)
{ {
id = ++idCounter;
ControlChangeID = 1; ControlChangeID = 1;
} }
Control::Control(const Control& Control) Control::Control(const Control& Control)
: type(Control.type), : type(Control.type),
id(Control.id), id(Control::noParent),
label(Control.label), label(Control.label),
callback(Control.callback), callback(Control.callback),
value(Control.value), value(Control.value),
color(Control.color), color(Control.color),
visible(Control.visible), visible(Control.visible),
parentControl(Control.parentControl), parentControl(Control.parentControl),
next(Control.next), ControlChangeID(Control.ControlChangeID)
ControlChangeID(Control.ControlChangeID)
{ } { }
void Control::SendCallback(int type) void Control::SendCallback(int type)
@ -42,15 +39,15 @@ void Control::SendCallback(int type)
} }
} }
void Control::DeleteControl() void Control::DeleteControl()
{ {
_ToBeDeleted = true; _ToBeDeleted = true;
callback = nullptr; callback = nullptr;
} }
bool Control::MarshalControl(JsonObject & _item, bool Control::MarshalControl(JsonObject & _item,
bool refresh, bool refresh,
uint32_t StartingOffset, uint32_t StartingOffset,
uint32_t AvailMarshaledLength, uint32_t AvailMarshaledLength,
uint32_t &EstimatedMarshaledLength) uint32_t &EstimatedMarshaledLength)
{ {
@ -225,7 +222,7 @@ void Control::onWsEvent(String & cmd, String& data)
SendCallback(B_DOWN); SendCallback(B_DOWN);
break; break;
} }
if (cmd.equals(F("bup"))) if (cmd.equals(F("bup")))
{ {
SendCallback(B_UP); SendCallback(B_UP);
@ -237,7 +234,7 @@ void Control::onWsEvent(String & cmd, String& data)
SendCallback(P_FOR_DOWN); SendCallback(P_FOR_DOWN);
break; break;
} }
if (cmd.equals(F("pfup"))) if (cmd.equals(F("pfup")))
{ {
SendCallback(P_FOR_UP); SendCallback(P_FOR_UP);
@ -249,7 +246,6 @@ void Control::onWsEvent(String & cmd, String& data)
SendCallback(P_LEFT_DOWN); SendCallback(P_LEFT_DOWN);
break; break;
} }
else if (cmd.equals(F("plup"))) else if (cmd.equals(F("plup")))
{ {
SendCallback(P_LEFT_UP); SendCallback(P_LEFT_UP);