First, some background...
I am working on C project that will run on a micro controller. There are 4 buttons (+, -, enter, and cancel)
and a 2x16 character LCD that will be used for the user interface. I've got a handle using the LCD and input
buttons so far. Although this project is micro controller-based, my questions are not specific to the micro.
where I'm stuck...
I am looking for help (example code would be great as I'm pretty new to this) on creating the best data
structure for the menu and mechanism for navigating through it. I want to maintain the ability to add and delete menus in my code (not at runtime) and still be able to use the code that navigates through the menus without doing a lot of recoding. I did some experimentation, and was able to do this without a hitch with a simple array, but I'm thinking I will need to use a more flexible data type, so I can keep menu text and the
associated parameters (which may vary in type) for the menu text together.
I came up with the following nested structure design. I don't even know if I'm on the right track or if the
code below is possible, but I thought it might be helpful to see what I've been working with.
char mainMenuText; //this is just some kind of title screen
char menu_1_item_1_Text; // for each setting in the gui, there is display text
int menu_1_item_1_Value; // ...and a corresponding value.
I intend for it to end up looking something like as follows:
Menu 1 item 1 = (some number)
Menu 1 item 2 = (some number)
Menu 1 item 3 = (some number)
Menu 2 item 1 = (some number)
Menu 2 item 2 = (some number)
I want to be able to "scroll" through the choices with my + and - buttons, so if I hit the "-" button when
the main menu loads, I would be at the last top level menu choice (Menu 2, in this case). If I hit the "+"
button, when the Main Menu loads, I would be on Menu 1. The cancel button will go back a level and the enter
button will confirm a choice.
Thanks in advance!