ESPUI function call addControl

ESPUI is a library to build webinterfaces on an ESP8266 or ESP32

It has a lot of UI-elements one is a input-number-field
image

There are two ways to define them

using

ESPUIClass::number(
//ie.
ESPUI.number("Numbertest", &numberCall, ControlColor::Alizarin, 5, 0, 10);

where the "0" and the "10" are min and max-limits

This method works only if the website has no tabs

I want to create a web-interface with tabs
The documentaion says that this requires to use the addControl-function

example

  AdjustNr_ID = ESPUI.addControl(ControlType::Number, "Click Up/Down Number:", 50, ControlColor::Alizarin, myTab_Settings3_ID, &numberCallback);

In the example code inside the library (like the codeline above) the addControl-method has no min / max-parameters.

This is how the sourcecode of the "number"-function and the "addControl"-function looks like (inside file ESPUI.cpp)

uint16_t ESPUIClass::number(
    const char* label, void (*callback)(Control*, int), 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);
    addControl(ControlType::Max, label, String(max), ControlColor::None, numberId);
    return numberId;
}


uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color,
    uint16_t parentControl, void (*callback)(Control*, int))
{
    Control* control = new Control(type, label, callback, value, color, true, parentControl);

    if (this->controls == nullptr)
    {
        this->controls = control;
    }
    else
    {
        Control* iterator = this->controls;

        while (iterator->next != nullptr)
        {
            iterator = iterator->next;
        }

        iterator->next = control;
    }

    this->controlCount++;

    return control->id;
}

what baffles me is that the number-function has three calls to function addControl
first for "number"
second for "min"
third for "max"

uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback);

addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);

addControl(ControlType::Max, label, String(max), ControlColor::None, numberId);

As the documentation says for website with tabs I'm forced to use the addControl-function which has less parameters

how can I set the min and max-values when calling the addControl-function?

best regards Stefan

I've never used that library. But it looks like you just need to make two more calls to 'addControl()' to set the min and max types … just like the 'number()' function does. Use the value returned by the first call in each of the subsequent calls as the 'parentControl' argument (fourth parameter).

Something like below. I don't have that library installed, so you'll need to play with it to get the function arguments right.

  AdjustNr_ID = ESPUI.addControl(ControlType::Number, "Numbertest", 50, ControlColor::Alizarin, myTab_Settings3_ID, &numberCallback);
  ESPUI.addControl(ControlType::Min, "Numbertest", String(min), ControlColor::None, AdjustNr_ID);
  ESPUI.addControl(ControlType::Max, "Numbertest", String(max), ControlColor::None, AdjustNr_ID);

Hi gfvalvo,

yes this works! Thank you very much

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.