First of all, let me say that you make real good progress. I know it is somehow difficult to understand the concept, but i think you got the idea already.
M2_ROOT:
Yes, it usually referes to a VLIST or ALIGN element. In fact it should refer to some toplevel element. Usually a dialog box looks like this:
ALIGN contains VLIST or GRIDLIST, which contain atomic elements like ROOT or BUTTON. Of course, for more complex dialog boxes, VLIST/HLIST/GRIDLIST can be nested with each other. So M2_ROOT refers to the ALIGN element.
So let me have a look at your top level menu:
M2_ROOT(el_vlistmm_m1, NULL, "WINDOWS", &top_el_vlist_submenu1); // main menu 1
M2_ROOT(el_vlistmm_m2, NULL, "TEMPERATURES", &top_el_vlist_submenu2); // main menu 2
M2_LIST(list_vlistmm) = { &el_vlistmm_m1, &el_vlistmm_m2, };
M2_VLIST(el_vlistmm_list, NULL, list_vlistmm);
M2_ALIGN( top_el_vlist_mainmenu, "-1|1W64H64", &el_vlistmm_list );
A classical menu with two entries. The two ROOT elements will directly jump to a different menu/dialogbox, which are given as "top_el_vlist_submenu1" and "top_el_vlist_submenu2"
One of your question was: How to jump back. There is no concept of "jumping back". Instead you need to add a ROOT element in the submenu, which jumps back to the previous/top level menu.
So in "top_el_vlist_submenu1" you may want to jump back to "top_el_vlist_mainmenu". This is obviously done by:
M2_ROOT(el_back_to_top, NULL, "MAIN MENU", &top_el_vlist_mainmenu);
Let me apply this to your WINDOWS Menu:
M2_ROOT( top_el_vlist_submenu1, NULL, "ALL", &el_vlist_subsub1 );
M2_ROOT( top_el_vlist_submenu2, NULL, "ROOM 1", &el_vlist_subsub2 );
M2_ROOT(el_back_to_top, NULL, "MAIN MENU", &top_el_vlist_mainmenu);
M2_LIST(list_vlistsum) = { &top_el_vlist_submenu1, &top_el_vlist_submenu2, &el_back_to_top };
M2_VLIST(el_vlistsum_list, NULL, list_vlistsum);
M2_ALIGN( top_el_vlist_submenu1, "-1|1W64H64", &el_vlistsum_list);
However there are some mistakes in your code.
First: Each element name (first argument) must be unique. So the two ROOT elements need to be renamed. Same applies to LIST and VLIST.
M2_ROOT( el_root_all, NULL, "ALL", &el_vlist_subsub1 );
M2_ROOT( el_root_room1, NULL, "ROOM 1", &el_vlist_subsub2 );
M2_ROOT(el_back_to_top, NULL, "MAIN MENU", &top_el_vlist_mainmenu);
M2_LIST(list_windows) = { &el_root_all, &el_root_room1, &el_back_to_top };
M2_VLIST(el_windows_vlist, NULL, list_windows);
M2_ALIGN( top_el_vlist_submenu1, "-1|1W64H64", &el_windows_vlist);
Then there is another problem, that needs to be solved. Now, your WINDOWS menu refers to the MAIN MENU und the MAIN MENU refers to the WINDOWS menu. Since there is a sequencial list of menu definitions, one of the menus need to defined first and will lead to an error (undeclared identifier or something) when refering to the later menu.
Solution is to add a "extern" declaration, which does not define the menu, but makes it available for use before the actual definition.
In your case, you need to use:
M2_EXTERN_ALIGN(top_el_vlist_mainmenu);
So to complete the WINDWOS menu, it should look like this:
M2_EXTERN_ALIGN(top_el_vlist_mainmenu); // forward declaration
M2_ROOT( el_root_all, NULL, "ALL", &el_vlist_subsub1 );
M2_ROOT( el_root_room1, NULL, "ROOM 1", &el_vlist_subsub2 );
M2_ROOT(el_back_to_top, NULL, "MAIN MENU", &top_el_vlist_mainmenu);
M2_LIST(list_windows) = { &el_root_all, &el_root_room1, &el_back_to_top };
M2_VLIST(el_windows_vlist, NULL, list_windows);
M2_ALIGN( top_el_vlist_submenu1, "-1|1W64H64", &el_windows_vlist);
// code for "top_el_vlist_mainmenu" will follow here
// ...
Another question is related to OPEN and CLOSE. First you should be clear, what exactly should happen here.
Let me assume, you want to open and close a window.
Independently from M2tklib, you will need a state machine for the window (for each window if there are more windows).
The state machine will have more than just the two states OPEN and CLOSE, thare are also: OPENING and CLOSING, which usually refere to some engines which perform the opening and closing of the windows. So the transitions of the state machine are:
OPEN --> CLOSING
CLOSING --> CLOSE
CLOSE --> OPENING
OPENING --> OPEN
Of course there might be more transitions, like
CLOSING --> OPENING
if you change your mind during closing.
Leaving a state depends on several conditions. Leaving "CLOSING" state and entering "CLOSE" state usually is done if some sensor detects, that the window is closed.
After this short discussion of some independet state machine, here is the connection to M2tklib: It can serve as a trigger to leave the OPEN state of the "CLOSE" menu is pressed. For example the CLOSE menu may do this:
- Check if the window is open and the state is OPEN
- Start the engine to close the window
- move the state of the state machine above to CLOSING
All in all you may want to use M2_BUTTON instead of M2_ROOT, because M2_BUTTON allows you to attach a procedure which in turn can contain any advice to your actors and state machines.
To complete the discussion on state machines and M2tklib, please have a look at tutorial 5 (Google Code Archive - Long-term storage for Google Code Project Hosting.). It partly repeats what i wrote here. Especially have a look at the STOP state and how M2tklib starts and stops the state machine.
So, i hope i answered these two questions:
- create buttons and callbacks for them
- make exit button work .
For CLOSE and OPEN, consider buttons and callbacks, for the exit button use M2_ROOT to the main menu (or previous menu)
-Center the whole menu at top center
Instead of
M2_ALIGN( top_el_vlist_submenu1, "-1|1W64H64", &el_windows_vlist);
use
M2_ALIGN( top_el_vlist_submenu1, "-1|2W64H64", &el_windows_vlist);
as described in the reference manual.
- make labels in each sub menu so i can see where am i in menu
Here is a simple solution:
M2_LABEL(el_vlistmm_label, NULL, "MAIN MENU");
M2_ROOT(el_vlistmm_m1, NULL, "WINDOWS", &top_el_vlist_submenu1); // main menu 1
M2_ROOT(el_vlistmm_m2, NULL, "TEMPERATURES", &top_el_vlist_submenu2); // main menu 2
M2_LIST(list_vlistmm) = { &el_vlistmm_label, &el_vlistmm_m1, &el_vlistmm_m2 };
M2_VLIST(el_vlistmm_list, NULL, list_vlistmm);
M2_ALIGN( top_el_vlist_mainmenu, "-1|1W64H64", &el_vlistmm_list );
hope, i got all your questions answered.
Oliver