mirror of
https://github.com/s00500/ESPUI.git
synced 2025-07-06 04:30:18 +00:00
introduce lambda
This commit is contained in:
@ -627,27 +627,25 @@ uint16_t ESPUIClass::addControl(ControlType type, const char* label, const Strin
|
||||
uint16_t ESPUIClass::addControl(
|
||||
ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl)
|
||||
{
|
||||
return addControl(type, label, value, color, parentControl, nullptr);
|
||||
return addControl(type, label, value, color, parentControl, new Control(type, label, nullptr, value, color, true, parentControl));
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color,
|
||||
uint16_t parentControl, void (*callback)(Control*, int))
|
||||
uint16_t parentControl, std::function<void(Control*, int)> callback)
|
||||
{
|
||||
uint16_t id = addControl(type, label, value, color, parentControl, nullptr, nullptr);
|
||||
uint16_t id = addControl(type, label, value, color, parentControl);
|
||||
// set the original style callback
|
||||
getControl(id)->callback = callback;
|
||||
return id;
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color,
|
||||
uint16_t parentControl, void (*callback)(Control*, int, void*), void* UserData)
|
||||
uint16_t ESPUIClass::addControl(
|
||||
ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, Control* control)
|
||||
{
|
||||
#ifdef ESP32
|
||||
xSemaphoreTake(ControlsSemaphore, portMAX_DELAY);
|
||||
#endif // def ESP32
|
||||
|
||||
Control* control = new Control(type, label, callback, UserData, value, color, true, parentControl);
|
||||
|
||||
if (controls == nullptr)
|
||||
{
|
||||
controls = control;
|
||||
@ -753,70 +751,37 @@ uint16_t ESPUIClass::graph(const char* label, ControlColor color)
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::slider(
|
||||
const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min, int max)
|
||||
{
|
||||
uint16_t id = slider(label, nullptr, color, value, min, max, nullptr);
|
||||
getControl(id)->callback = callback;
|
||||
return id;
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value,
|
||||
int min, int max, void* userData)
|
||||
const char* label, std::function<void(Control*, int)> callback, ControlColor color, int value, int min, int max)
|
||||
{
|
||||
uint16_t sliderId
|
||||
= addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback, userData);
|
||||
= addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback);
|
||||
addControl(ControlType::Min, label, String(min), ControlColor::None, sliderId);
|
||||
addControl(ControlType::Max, label, String(max), ControlColor::None, sliderId);
|
||||
|
||||
return sliderId;
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::button(const char* label, void (*callback)(Control*, int), ControlColor color, const String& value)
|
||||
uint16_t ESPUIClass::button(const char* label, std::function<void(Control*, int)> callback, ControlColor color, const String& value)
|
||||
{
|
||||
return addControl(ControlType::Button, label, value, color, Control::noParent, callback);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::button(
|
||||
const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
|
||||
{
|
||||
return addControl(ControlType::Button, label, value, color, Control::noParent, callback, UserData);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int), ControlColor color, bool startState)
|
||||
uint16_t ESPUIClass::switcher(const char* label, std::function<void(Control*, int)> callback, ControlColor color, bool startState)
|
||||
{
|
||||
return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::switcher(
|
||||
const char* label, void (*callback)(Control*, int, void*), ControlColor color, bool startState, void* UserData)
|
||||
{
|
||||
return addControl(
|
||||
ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback, UserData);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int), ControlColor color)
|
||||
uint16_t ESPUIClass::pad(const char* label, std::function<void(Control*, int)> callback, ControlColor color)
|
||||
{
|
||||
return addControl(ControlType::Pad, label, "", color, Control::noParent, callback);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
|
||||
{
|
||||
return addControl(ControlType::Pad, label, "", color, Control::noParent, callback, UserData);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*, int), ControlColor color)
|
||||
uint16_t ESPUIClass::padWithCenter(const char* label, std::function<void(Control*, int)> callback, ControlColor color)
|
||||
{
|
||||
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::padWithCenter(
|
||||
const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
|
||||
{
|
||||
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback, UserData);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::number(
|
||||
const char* label, void (*callback)(Control*, int), ControlColor color, int number, int min, int max)
|
||||
const char* label, std::function<void(Control*, int)> callback, ControlColor color, int number, int min, int max)
|
||||
{
|
||||
uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback);
|
||||
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
|
||||
@ -824,16 +789,6 @@ uint16_t ESPUIClass::number(
|
||||
return numberId;
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int number,
|
||||
int min, int max, void* UserData)
|
||||
{
|
||||
uint16_t numberId
|
||||
= addControl(ControlType::Number, label, String(number), color, Control::noParent, callback, UserData);
|
||||
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
|
||||
addControl(ControlType::Max, label, String(max), ControlColor::None, numberId);
|
||||
return numberId;
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::gauge(const char* label, ControlColor color, int number, int min, int max)
|
||||
{
|
||||
uint16_t numberId = addControl(ControlType::Gauge, label, String(number), color, Control::noParent);
|
||||
@ -847,28 +802,16 @@ uint16_t ESPUIClass::separator(const char* label)
|
||||
return addControl(ControlType::Separator, label, "", ControlColor::Alizarin, Control::noParent, nullptr);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::accelerometer(const char* label, void (*callback)(Control*, int), ControlColor color)
|
||||
uint16_t ESPUIClass::accelerometer(const char* label, std::function<void(Control*, int)> callback, ControlColor color)
|
||||
{
|
||||
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::accelerometer(
|
||||
const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
|
||||
{
|
||||
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback, UserData);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int), ControlColor color, const String& value)
|
||||
uint16_t ESPUIClass::text(const char* label, std::function<void(Control*, int)> callback, ControlColor color, const String& value)
|
||||
{
|
||||
return addControl(ControlType::Text, label, value, color, Control::noParent, callback);
|
||||
}
|
||||
|
||||
uint16_t ESPUIClass::text(
|
||||
const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
|
||||
{
|
||||
return addControl(ControlType::Text, label, value, color, Control::noParent, callback, UserData);
|
||||
}
|
||||
|
||||
Control* ESPUIClass::getControl(uint16_t id)
|
||||
{
|
||||
#ifdef ESP32
|
||||
|
Reference in New Issue
Block a user