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

Add selected to runOnce #107

Open
benhul opened this issue Sep 21, 2020 · 7 comments
Open

Add selected to runOnce #107

benhul opened this issue Sep 21, 2020 · 7 comments

Comments

@benhul
Copy link

benhul commented Sep 21, 2020

Your library works great. I use it to set the options for my program.

Maybe you can add an optional selected field to the .runOnce function.

PXL_20200921_123249421

I use a menu to set preferences and I use a \t to show the current value to the right on the same line. After clicking +, 5 is added to the current value. I would like to renew the menu with the new value (which I can) but the same (second) row selected (which I can't).

I made the change for myself (it's only 4 lines of code::smile: ) but others could benefit.

int16_t ezMenu::runOnce(int selected) {
	_selected = selected;           // or selected - 1 to make selected 1 based
	return runOnce();
}

Or put it in a more generic menu.setSelected(int selected) function.

@vkichline
Copy link
Collaborator

Good suggestion, @benhul; it would be helpful to be able to set the menu selection.
Recently we added a way to access the current menu from an event; this won't help with your issue, but it makes me think it would be better to add an ezMenu::setSelection(int n) instead; then the selection could be altered by a periodic event as well as in a call to runOnce(). Maybe it would be setPick(int n) as that seems more consistent if the function uses 1-based indexes for the items as everywhere else.
I think all you would have to do (if this function were added) would be:

    menu.setPick(2);
    menu.runOnce();

Would it work for you if it were implemented this way?

@benhul
Copy link
Author

benhul commented Sep 25, 2020

Good name setPick and indeed it's better to have it one based. I (would) use:

int current_row = 1;
//...
    menu.setPick(current_row);
    runOnce();
    current_row = menu.pick();
    ....

Have fun.

@UT2UH
Copy link

UT2UH commented Sep 25, 2020

You can write color managers functions like this and call them as advanced function from main menu at menu item's selection press. You can also add callingMenu->pick(); to find the color selected.

volatile uint8_t colorValue;
bool mngColor(ezMenu* callingMenu){
  uint8_t colorPicked = callingMenu->pick();
  colorValue += 5; // or colorValue[colorPicked] +=5;
  callingMenu->setCaption("color", "Color\t" + String(colorValue));
  return true;
}

@benhul
Copy link
Author

benhul commented Sep 26, 2020

You're right, missed that one...

@MartinNohr
Copy link

I could use the setPick() idea as well. Any idea when this will be impemented?
Thanks.

@LennartHennigs
Copy link

Hey, I added these in my fork because I am building something similar:

master...LennartHennigs:master

@MartinNohr
Copy link

I don't think your code is completely correct.
void ezMenu::setItem(int index) {
_selected = index;
}
What happens if the menu was larger and had been scrolled? It doesn't display correctly in that case.

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

5 participants