Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » Dynamic menu creation or datalist

Author: NewOne
16/06/2021 20:42:54
Is there any example for dynamic creation of a Submenu or a datalist ?
I want to show a list of values (analog, boolean) in a Sumbenu. But the list can change at runtime, so i have to create this Menuitems at Runtime.
I believe that a datalist is the best way for my problem, but how to set Name, Value and Type of a row ?

Author: davetcc
17/06/2021 07:40:01
Hi there, with lists the data is always a zero-terminated string for display so you'd just convert the type you have to a string, eg format the number or boolean as a string. You can see lists used in many of the examples.

The way they work is that the render function that the designer generates for you will be called for each row of the list, starting at zero and going up to the number of rows you set in the list menu item. There's a full description of this here:

https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menu-item-types/list-menu-item/

Author: NewOne
17/06/2021 09:03:20
In many of the examples ? Where ? I could not find any example.... Can you send me a link to any examples ?

Author: davetcc
17/06/2021 09:31:41
A couple of examples with list menu items:

https://github.com/davetcc/tcMenuLib/blob/0d792a7c99f5e45a3e5253360cda507be44acc04/examples/keyboardEthernetShield/keyboardEthernetShield.ino#L252

https://github.com/davetcc/tcMenuLib/blob/0d792a7c99f5e45a3e5253360cda507be44acc04/examples/esp32Amplifier/esp32Amplifier_main.cpp#L172

Also, see the documentation I provided earlier, as it describes the background.

Author: davetcc
17/06/2021 10:11:14
So basically:

1. Add a list to you menu somewhere, it will generate you a template render function in the sketch, somewhat like the two attached.

2. Then this function will be called every time anything needs to be drawn (or even when an item is selected).

---

Building a custom menu structure.

EDIT also you can add any type of menu item from code at runtime, every menu item type is documented here (with a sub page for each type): https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menu-item-types/

You basically link the menu items together in a linked list. To insert the first menu item you can add it via menuMgr: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/

Author: NewOne
17/06/2021 16:39:29
Thanks

Author: davetcc
17/06/2021 17:46:27
Although it's on a branch in the middle of development, there's a new example that you could look at:

https://github.com/davetcc/tcMenuLib/tree/remote-refactor-feature/examples/dynamicMenuItems




Register / Login  |  Desktop view  |  Jump to top of page