[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 

Dynamic menu creation or datalist RSS feed
Forum Index » tcMenu Arduinio library
Author Message
NewOne


Joined: Oct 21, 2020
Messages: 19
Offline
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 ?
davetcc


Joined: Jan 19, 2019
Messages: 517
Offline
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/
NewOne


Joined: Oct 21, 2020
Messages: 19
Offline
In many of the examples ? Where ? I could not find any example.... Can you send me a link to any examples ?
davetcc


Joined: Jan 19, 2019
Messages: 517
Offline
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.
davetcc


Joined: Jan 19, 2019
Messages: 517
Offline
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/
NewOne


Joined: Oct 21, 2020
Messages: 19
Offline
Thanks
davetcc


Joined: Jan 19, 2019
Messages: 517
Offline
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
 
Forum Index » tcMenu Arduinio library
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.