Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu item reuse #71

Open
pserotta opened this issue Oct 16, 2017 · 1 comment
Open

Menu item reuse #71

pserotta opened this issue Oct 16, 2017 · 1 comment

Comments

@pserotta
Copy link

pserotta commented Oct 16, 2017

Hello,
First, I would like to thank you for the menu system it seems well thought out.
But I have a few questions.

  1. In my use case I will be re-using menu items in multiple menus. I think this is possible but I am having some confusion.
    Here is an example, this is for a sprinkler controller if it helps.

The Menu would like like this:

Manual
---Valve 1
------Set Minutes
Program
---Valve 1
------Set Minutes

Code snippet:

// Define menus and menu items
Menu mu1("Manual");
Menu v1("Valve 1");
MenuItem setmin("Set Minutes",&on_setMinutes_selected);
Menu mu2("Program");
Menu mu3("Valve Run Time");

// Build Menu
ms.get_root_menu().add_menu(&mu1); // Add "Manual" to root menu
mu1.add_menu(&v1); // Add "Valve 1" menu under "Manual"
v1.add_item(&setmin); // Add "Set Minutes" under "Valve 1"
ms.get_root_menu().add_menu(&mu2); // Add "Program" to root menu
mu2.add_menu(&mu3); // Add "Valve Run Time" menu under "Program"
mu3.add_menu(&v1); // Add "Valve 1" (and "Set Minutes") under "Valve Run Time"

My question is in the callback function on_setMinutes_selected, I need to know if the menu path started at "Program" or "Manual". Is there a way to keep track of the menu path taken to a given callback.
It would be a bit wasteful if different MenuItems were needed for each endpoint callback.

  1. I see that support for NumericMenuItem but I am not understanding its purpose. Can you elaborate with a small sample?

Thank you!

@jonblack
Copy link
Owner

In your example I think they are two different menu items: one in the "manual" context and the other in the "program" context. If you really want code reuse, have two callback functions call a common setMinutes function.

As for actually reusing a menu item, this isn't possible I'm afraid. You could hack it by adding path information to the menu name, but I doubt you want that.

For NumericMenuItem check out the serial_nav example. In short, the NumericMenuItem is a concrete MenuItem that holds a numeric value that can be incremented or decremented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants