s00500 / ESPUI

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

How to change sender->id? #312

Closed baylf2000 closed 3 weeks ago

baylf2000 commented 3 weeks ago

I'm trying to work out how to modify the sender id as presented to the callback function. In the examples given, like the below, the method specifies a callback "textCall"...

ESPUI.text("Text Test:", &textCall, ControlColor::Alizarin, "a Text Field");

And in the examples, that callback contains a "Control" parameter with an id available as sender->id.

void textCall(Control* sender, int type)
{
    Serial.print("Text: ID: ");
    Serial.print(sender->id);
    Serial.print(", Value: ");
    Serial.println(sender->value);
}

In my tests with multiple fields, it appears this value is dynamically generated, as each field contains a different id. My question is, are we able to set this in advance? I'd like to use a single callback for multiple fields, however I'd need a way to determine which field is calling the callback.

baylf2000 commented 3 weeks ago

Never mind, I answered my own question. That id value is used internally for tying the html components to their values. We're supposed to use the void* userparameter.

MartinMueller2003 commented 3 weeks ago

Each instance of control has a unique id. Each control pointer is unique. You can keep a table of control pointers and search through it or you can keep a map of ID to some structure you have to track them.

Best is to use a lambda for each control type