source: npl/mediabox/lcdproc_edwin/src/docs/menustuff.txt

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 4.1 KB
Line 
1Allo...  (warning:  this was written as I thought it up :)
2
3Ideas for implementing menus...
4
5We've got a data structure called "Menu_Item", which has (for starters):
6
7        Title           -- Text to display
8        Child           -- Sub-Menu to recurse into, if item is picked
9        Exec Function   -- Function to call if the item is picked
10
11An item must not have both a child and an exec function.
12
13The DoMenu(main_menu) handles all input and either calls ExecFunction,
14if the picked item has one; or recurses into the Child menu.  The
15ExecFunction returns a value to specify whether the menus should go
16away, back up one level, or stay as-is.  Also, a menu title (label)
17can be specified by giving neither a Child nor a Function.
18
19The up/down arrows, blinking, scrolling, etc, are handled by DoMenu().
20
21This gives us the functionality of a standard pull-down menu.
22However, we need more functionality than that.  We need checkboxes,
23sliders, and a way to move items up/down.
24
25So...
26
27The ExecFunction should take a parameter, telling whether the item was
28simply picked, or if it had a +/- pressed on it.  This lets us change
29a value from the menu.
30
31We should also add another function to the MenuItem struct:
32
33        Data Function   -- returns true, false, or 0-255.
34
35This lets us find out if a checkbox should be checked, or where a
36slider should be.  DoMenu() will figure out what widget it's dealing
37with (if any), and adjust its display accordingly.
38
39But we still can't move menu items up/down.
40
41
42...
43
44
45Perhaps...  This might work better:
46
47        Title           -- Text
48        Type            -- menu,  function, checkbox,  slider,   mover
49        Data            -- Child, ExecFunc, CheckFunc, SlidFunc, ???
50
51When an item is picked, DoMenu() decides what to do based on type.
52--"Menus" will recurse into the "data", assuming it's a child menu.
53--"Function"-type items will have their function called. 
54--CheckBox-type items will have their function called with a "read"
55  parameter to get an on/off signal, and called with a "set" signal when
56  picked.
57--Sliders will have the same "read" thing, and the "set" function will
58  take a plus or minus parameter.
59--The Movers will act like a label until picked, and then the +/- keys
60  will both rearrange the menu, and send the item a signal of some sort
61  to indicate what happened.  It'll act like a label again after the
62  user presses Enter again.
63
64The "Data" field will really be a "void *", which is C's "generic"
65data type...
66
67Anyway, this sort of thing would be declared this way:
68
69========================================================================
70
71Menu MainMenu = {
72        "MENU",         NULL,           NULL,   // Title
73        "Options",      MENU_TYPE,      (void *)OptionsMenu,
74        "Kill LCDproc", FUNC_TYPE,      (void *)Shutdown_func,
75        NULL,           NULL,           NULL,
76};
77
78Menu OptionsMenu = {
79        "OPTIONS",      NULL,           NULL,   // Title
80        "24-hour Time", CHEK_TYPE,      (void *)Time24_func,
81        "Contrast...",  SLID_TYPE,      (void *)Contrast_func,
82        NULL,           NULL,           NULL,
83};
84
85
86///////////////// Elsewhere, we declare these...
87
88void Shutdown_func()
89{
90  // Do something here...
91  return MENU_KILL;     // or MENU_CLOSE, or MENU_OK, or MENU_ERROR
92}
93
94int Time24_func(int input)
95{
96  if(input == READ) return status;
97  if(input == SELECT) toggle_status();  // does something.
98  return (status | MENU_OK);
99        // The status is "or"-ed with the MENU value to let DoMenu()
100        // know what to do after selecting the item.  (two return
101        // values in one.  :)
102
103        // Also, "MENU_OK" happens to be zero, so it doesn't matter
104        // unless you want something else (like MENU_CLOSE)
105}
106
107int Contrast_func(int input)
108{
109  if(input == READ) return status;
110  if(input == PLUS) increment_status(); // does something.
111  if(input == MINUS) decrement_status();// does something.
112  return (status | MENU_OK);
113}
114
115
116========================================================================
117
118The main reason I like this is that it completely separates the menu
119definitions from the code which actually handles it.  We have *one*
120function which does everything menu-related.
121
122Also, we'd include a table of some sort to match names to functions,
123so that the user can create their own menus with the functionality
124already provided.  (including user-defined "functions", which will be
125rather limited but still useful)
126
Note: See TracBrowser for help on using the repository browser.