neu-rah / ArduinoMenu

Arduino generic menu/interactivity system
GNU Lesser General Public License v2.1
951 stars 191 forks source link

Use updateEvent to trigger a callback in choose or select fields #288

Closed waisens closed 4 years ago

waisens commented 4 years ago

Hi rui: I am playing with Arduino again. Is it possible to call a callback function when updating a value selected by a "select" or "choose" field?

Menu::select& Modes = new Menu::select("mode", mode, sizeof(Modes_Data) / sizeof(prompt), Modes_Data, (Menu::callback)mode_cb, updateEvent);

With a toggle field it works using "enterEvent".

toggle& Modes = new toggle("mode", mode, sizeof(Modes_Data) / sizeof(prompt), Modes_Data, (Menu::callback)mode_cb, enterEvent);

But with the fields "select" or "choose" I cannot use "enterEvent" and when I use "updateEvent" the function is not called.

Note: "updateEvent" works correctly when I edit numerical values for example

menuField <typeof(deltaVal)> &Delta = *new menuField<typeof(deltaVal)> (deltaVal, "delta", "m", 0.1, 10.0, 1, 0.1, (Menu::callback)deltaVal_cb, updateEvent);

Thank you in advance

Esp32 core 1.01 ArduinoMenu 4.17.25 Constructor: U8G2_SSD1306_128X64_NONAME_F_HW_I2C

neu-rah commented 4 years ago

yes, this example might help, some events can be handled on the parent element, and there are also focus/blur events.

https://github.com/neu-rah/ArduinoMenu/blob/master/examples/handlers/handlers/handlers.ino

let it run and watch the printout

just let me know if you need more help

waisens commented 4 years ago

Thank you!!! "exitEvent" works as I expected

Menu::select& Modes = new Menu::select("mode", mode, sizeof(Modes_Data) / sizeof(prompt), Modes_Data, (Menu::callback)mode_cb, exitEvent);

Menu::choose& Modes = new Menu::choose("mode", mode, sizeof(Modes_Data) / sizeof(prompt), Modes_Data, (Menu::callback)mode_cb, exitEvent);