[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 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

menuItems with changeble Names / const anymenuinfo RSS feed
Forum Index » tcMenu Arduinio library
Author Message
bitz


Joined: Apr 1, 2020
Messages: 9
Offline
Hi Dave,

Menuitems seem to have Name in Anymenuinfo, which is const.

In my usecase, the name of one some of the menuitems should be changeable by the user.
We have 5 or 6 drumpads, each drum should be configurable through a menu (or rather submenu).
The "drums" would be typically named after the sound they produce eg. "highTom" or "snare".

The user can change the sound each drumpad produces and he would expect
to see the name in the menu that leads to the config of that drumpad.
So i would like to change the name of that item.

I considered three ways:

1. runtimeitem: still stuck with const Anymenuinfo, or do i see that wrong ?
2. make Anymenuinfo NOT const, i have enough ram, but thats really deep into your code, allthough the constructor for submenuitem compiles without const, that has probably lots of unitended side effects.
3. create a sibling of the submenitem class with changeble Anymenuinfo, that seems to be not so big of an issue, most of the code would be inherited.

Allthough 3 is my favorite, would you mind giving me a hint ?
thanks in advance,
Regards,
bitz


davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
Hi there,

The safest option in the current version is probably to subclass the submenu item (option 3 basically). Let me know if that works for you, if not I'll have to look into the possibility of other options. Certainly don't remove const on any of the PROGMEM definitions, you'll get unexpected results on many processors.

The longer-term solution may look more like a runtime menu item as that uses a callback mechanism to get the name, so you could set name at will when requested. However, right now it wouldn't work because it's not a sub-menu type and MenuManager object expects submenu's to be of a specific type SubMenuItem. Going forward a subclass of RuntimeMenuItem may need to be able to fulfill the same contract. Maybe in a future version, I could create a new interface called something like IMenuWithChildren and then make a version of RuntimeMenuItem that implemented it (maybe RuntimeSubMenuItem) along with SubMenuItem.

So in summary, my vote's for option 3 right now if that's workable.
bitz


Joined: Apr 1, 2020
Messages: 9
Offline
Thanks for your assessment & help.
Will try subclassing and see how it goes.
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
Raised https://github.com/davetcc/tcMenuLib/issues/55 to come up with various plans around this and implement something.
bitz


Joined: Apr 1, 2020
Messages: 9
Offline
Here the promised Feedback:
Actually I didn't subclass, rather took the shortcut.
Means: anymenuinfo beenig variable works OK in my case, for an action menu item. I looked into the lib code an the text/name part is only touched once with a "savecpy" (or so) to buffer. That doesn't need to be const.

Can post some code if you are interested...

Regards, bitz
 
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.