[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 

Example / code snippet to make a menu item visible/invisble on button long press? RSS feed
Forum Index » tcMenu Arduinio library
Author Message
hackintoshlover12


Joined: Nov 17, 2021
Messages: 3
Offline
Hey Guys,
I was trying to do some code to make one or more menu item visible/invisible by pressing the switch of attached encoder for more than 5 seconds.
Any help on how i can achieve the same would be very helpful.
I am stuck with it.
I know that the menu manager needs to be updated of the change by using notifyStructureChanged();
But how do i do that exactly?
davetcc


Joined: Jan 19, 2019
Messages: 599
Offline
Something similar to the following should do the job in most cases:

Lets say you had an event handler onMyEventOccurs:

void onMyEventOccurs() {
    menuMyItem.setVisible(false);
    // any other structural changes to the menu
    menuMgr.notifyStructureChanged();
}


But to capture the button click from the encoder, as I said the other day in the issue, your use-cases are slightly outside what the default input plugin supports, you'll need to manually handle the input as per https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-plugins/customise-menu-input-display-plugin/ and https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/#controlling-the-menu-items-manually as by default it is assumed tcMenu has control of input unless you take over the display.

Let me know if it doesn't work and I'll take a look, but normally this should work because the rendering facilities are listening for structure change events.
hackintoshlover12


Joined: Nov 17, 2021
Messages: 3
Offline
Hi Dave,
Thanks for sending the code snippet.
I tried the code snippet but i guess either menuMgr is not responding or i am doing something wrong.
Basically after changing menu item state i need to go back into main menu otherwise the changes don't display.
Kindly have a look at the attachments below.
https://drive.google.com/file/d/1uCWTkDWmbUL0khwaUNkY7hDvVIVP_v5l/view?usp=drivesdk
[Thumb - Screenshot (87).png]
 Filename Screenshot (87).png [Disk] Download
 Description No description given
 Filesize 69 Kbytes
 Downloaded:  837 time(s)

davetcc


Joined: Jan 19, 2019
Messages: 599
Offline
I'll probably need to try this exact case and see what happens to be honest. I'll feedback once I've had a chance to test it.
hackintoshlover12


Joined: Nov 17, 2021
Messages: 3
Offline
Thanks
I'll wait for your response
 
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.