Closed rfcohen closed 7 years ago
You're right that more documentation is needed for the renderer and I have an issue for it, just not enough time to work on it at the moment.
1 What portion of the renderer gets called when?
When you call MenuSystem::display()
it calls render
on the Renderer
passing a pointer the current Menu
.
The Renderer::render
function is the entry point to rendering. In here you need to decide which MenuComponent
's you're showing and call render
on them. So if you just want to show a single item, you'd get that item and call render
; if you want to show everything, you'd want to loop over the entire menu and call render
on each item.
When you call render
on a MenuComponent
is calls back to the appropriate render method in the renderer for the given component. For example, calling render
on a NumericMenuItem
will cause the NumericMenuItem
to call render_numeric_menu_item
. This function should have code to display this item.
2 Given a menu passed into the renderer, what's the right way to find its spot in the hierarchy for its parent? I'm hoping there's a simple way to get the menu's 'number' and use that as an index for drawing. So in my case, when the menu being drawn is mu1 is there a way to know that this is menu 1?
MenuComponent
don't know where they are in the heirarchy, and they shouldn't. You have two options for achieving numbering:
3 What's a component? A menu, a menu item, both, neither?
If you look in MenuSystem.h
you can see the classes for the library. The menu system is implemented using the composite design pattern. A MenuComponent
is the component part of this pattern, which acts as a base class from which the leaf MenuItem
and composite Menu
classes derive. This allows you to build up a nested hierarchy.
Great questions by the way. This will help me when I get around to writing some documentation.
This is great and thank you. There's enough here for me to make progress and get myself in trouble. :)
One more question - what is a NumericMenuItem
?
I hope JonBlack not will be upset if I help you in that.
So, a NumericMenuItem
and a CustomNumericMenuItem
are special menu items. If you like to use a menu item to execute something when you selecting it, just use a MenuItem
and use the method linked to it to do the logic what you want to execute.
The NumericMenuItem
is very handy when you like to use that menu item to store a numeric value, for example, the display brightness, or a language selector. The value will be rendered next to the menu item text like "Brightness=90" and if you press the select on that item it will be switched into edit mode and you will see something like "Brightness<90>" then pressing the up/down you can change the value what will be saved when you press the select again. You can use a custom renderer to show something like "Brightness=90%" or "Language=English" for more details check this example:
arduino-menusystem/examples/serial_nav/serial_nav.ino
Btw I'm happy to help if you will get in trouble. (I'm very close to finishing a woodchip boiler driver using a 320x480 TFT, with a multi-language menu system and settings saved back to SD card, (I will upload a youtube video very soon) so I struggled a lot to figure out how to make it nice for user and elegant from programming side.)
Can this issue be closed now?
I'm assuming this is now resolved. Re-open if it's not.
I'm trying to use this library as the model for visual menu system on a 320x480 LCD and I'm having trouble. I think each menu or menu item should have a unique identifier in a given menu.
menu.get_current_component_num()
seems to suggest that too.I have a menu structure set up like this:
And then I build up the menu like this:
I have a stupid simple renderer (btw, it would be nice if the documentation discussed the need for a renderer):
(the
switch
is a hack and all I could do to get what I wanted to draw)My questions: 1 What portion of the renderer gets called when? 2 Given a menu passed into the renderer, what's the right way to find its spot in the hierarchy for its parent? I'm hoping there's a simple way to get the menu's 'number' and use that as an index for drawing. So in my case, when the menu being drawn is
mu1
is there a way to know that this is menu 1? 3 What's a component? A menu, a menu item, both, neither?(I think that's all I have for now. Thanks)