I actually had a menu library I'd fiddled with myself. I'll see if I can dig it out. Personally, I stored the whole menu as structure where the values were functions that got executed when selected, something like:
var myMenu2 = {
"A Title":0,
"Back":function() {set_menu(myMenu); },
};
var myMenu = {
"Main Menu Title":0,
"A Submenu":function() { set_menu(myMenu2); },
"Run some code":function() { ... }
};
It made it relatively simple and easy to read. The menu code then just iterates over the object's fields and draws them, then when selected it runs the function.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I actually had a menu library I'd fiddled with myself. I'll see if I can dig it out. Personally, I stored the whole menu as structure where the values were functions that got executed when selected, something like:
It made it relatively simple and easy to read. The menu code then just iterates over the object's fields and draws them, then when selected it runs the function.