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

tcMenu Arduinio library » menuItems with changeble Names / const anymenuinfo

Author: bitz
16/04/2020 13:13:15
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



Author: davetcc
16/04/2020 17:04:03
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.

Author: bitz
16/04/2020 17:18:25
Thanks for your assessment & help.
Will try subclassing and see how it goes.

Author: davetcc
27/04/2020 11:09:00
Raised https://github.com/davetcc/tcMenuLib/issues/55 to come up with various plans around this and implement something.

Author: bitz
27/04/2020 13:53:38
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




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