Mercurial > molko
comparison libmlk-ui/ui/gridmenu.h @ 298:196264679079
misc: remove usage of bool
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 10 Mar 2021 18:49:08 +0100 |
parents | 08ab73b32832 |
children | d01e83210ca2 |
comparison
equal
deleted
inserted
replaced
297:6151152d009c | 298:196264679079 |
---|---|
17 */ | 17 */ |
18 | 18 |
19 #ifndef MOLKO_UI_GRIDMENU_H | 19 #ifndef MOLKO_UI_GRIDMENU_H |
20 #define MOLKO_UI_GRIDMENU_H | 20 #define MOLKO_UI_GRIDMENU_H |
21 | 21 |
22 /** | |
23 * \file gridmenu.h | |
24 * \brief GUI grid menu. | |
25 */ | |
26 | |
27 #include <stddef.h> | 22 #include <stddef.h> |
28 | 23 |
29 #include <core/core.h> | 24 #include <core/core.h> |
30 #include <core/texture.h> | 25 #include <core/texture.h> |
31 | 26 |
32 #include "label.h" | 27 #include "label.h" |
33 | 28 |
34 /** | |
35 * \brief Maximum number of entries. | |
36 */ | |
37 #define GRIDMENU_ENTRY_MAX (256) | 29 #define GRIDMENU_ENTRY_MAX (256) |
38 | 30 |
39 struct theme; | 31 struct theme; |
40 | 32 |
41 union event; | 33 union event; |
42 | 34 |
43 /** | |
44 * \brief Grid menu state. | |
45 */ | |
46 enum gridmenu_state { | 35 enum gridmenu_state { |
47 GRIDMENU_STATE_NONE, /*!< No state yet. */ | 36 GRIDMENU_STATE_NONE, |
48 GRIDMENU_STATE_ACTIVATED /*!< An entry has been selected. */ | 37 GRIDMENU_STATE_ACTIVATED |
49 }; | 38 }; |
50 | 39 |
51 /** | |
52 * \brief Internal texture representation. | |
53 * | |
54 * This structure contain several information for rendering the underlying grid | |
55 * into the screen. | |
56 */ | |
57 struct gridmenu_texture { | 40 struct gridmenu_texture { |
58 int rely; /*!< (-) View start in y. */ | 41 int rely; |
59 unsigned int relh; /*!< (-) Real texture height. */ | 42 unsigned int relh; |
60 unsigned int eltw; /*!< (-) Maximum label width */ | 43 unsigned int eltw; |
61 unsigned int elth; /*!< (-) Maximum label height. */ | 44 unsigned int elth; |
62 unsigned int spacev; /*!< (-) Vertical space between labels. */ | 45 unsigned int spacev; |
63 unsigned int spaceh; /*!< (-) Horizontal space between labels. */ | 46 unsigned int spaceh; |
64 struct texture texture; /*!< (*) The texture itself. */ | 47 struct texture texture; |
65 | |
66 /** | |
67 * (-) The list of labels. | |
68 */ | |
69 struct label labels[GRIDMENU_ENTRY_MAX]; | 48 struct label labels[GRIDMENU_ENTRY_MAX]; |
70 }; | 49 }; |
71 | 50 |
72 /** | |
73 * \brief Grid menu for selecting items. | |
74 * | |
75 * This menu offers a grid where user can specify a maximum number of columns to | |
76 * show entries. Content is automatically paginated vertically according to the | |
77 * current selection and the menu's length. | |
78 * | |
79 * It uses \ref frame.h and \ref label.h to draw elements so you may change the | |
80 * referenced theme if you want a different style. | |
81 * | |
82 * This module being a bit complex uses internal data for rendering that is | |
83 * repainted in case of event (when using \ref gridmenu_handle) but if you do | |
84 * modify the menu, you'll have to call \ref gridmenu_repaint yourself and you | |
85 * need to call it at least once before drawing. | |
86 */ | |
87 struct gridmenu { | 51 struct gridmenu { |
88 int x; /*!< (+) Position in x. */ | 52 int x; |
89 int y; /*!< (+) Position in y. */ | 53 int y; |
90 unsigned int w; /*!< (+) Width. */ | 54 unsigned int w; |
91 unsigned int h; /*!< (+) Height. */ | 55 unsigned int h; |
92 enum gridmenu_state state; /*!< (+) Menu state. */ | 56 enum gridmenu_state state; |
93 size_t selected; /*!< (+) User selection. */ | 57 size_t selected; |
94 const struct theme *theme; /*!< (+&?) Optional theme to use. */ | 58 const struct theme *theme; |
95 | |
96 /** | |
97 * (+&?) List of entries to show. | |
98 */ | |
99 const char *menu[GRIDMENU_ENTRY_MAX]; | 59 const char *menu[GRIDMENU_ENTRY_MAX]; |
100 | |
101 /** | |
102 * (+) Number of rows allowed per page. | |
103 */ | |
104 unsigned int nrows; | 60 unsigned int nrows; |
105 | |
106 /** | |
107 * (+) Number of columns allowed per page. | |
108 * | |
109 * \warning You must make sure to use a number of columns that can fit | |
110 * GRIDMENU_ENTRY_MAX, in other terms | |
111 * `GRIDMENU_ENTRY_MAX % ncols == 0` | |
112 */ | |
113 unsigned int ncols; | 61 unsigned int ncols; |
114 | |
115 /** | |
116 * (*) Internal grid menu texture. | |
117 */ | |
118 struct gridmenu_texture tex; | 62 struct gridmenu_texture tex; |
119 }; | 63 }; |
120 | 64 |
121 CORE_BEGIN_DECLS | 65 CORE_BEGIN_DECLS |
122 | 66 |
123 /** | |
124 * Reset the menu->state flag. | |
125 * | |
126 * \pre menu != NULL | |
127 * \param menu the menu to reset | |
128 */ | |
129 void | 67 void |
130 gridmenu_reset(struct gridmenu *menu); | 68 gridmenu_reset(struct gridmenu *); |
131 | 69 |
132 /** | |
133 * Rebuild internal texture for rendering. | |
134 * | |
135 * \pre menu != NULL | |
136 * \pre GRIDMENU_ENTRY_MAX % menu->ncols == 0 | |
137 * \param menu the menu to repaint | |
138 */ | |
139 void | 70 void |
140 gridmenu_repaint(struct gridmenu *menu); | 71 gridmenu_repaint(struct gridmenu *); |
141 | 72 |
142 /** | |
143 * Handle an event in the menu. | |
144 * | |
145 * Mouse click will test the coordinate of the mouse to check if the pointer is | |
146 * on a menu item region but keyboard events aren't so make sure to have user | |
147 * "focus" prior to calling this function. | |
148 * | |
149 * \pre menu != NULL | |
150 * \pre ev != NULL | |
151 * \param menu the menu to use | |
152 * \param ev the event | |
153 */ | |
154 void | 73 void |
155 gridmenu_handle(struct gridmenu *menu, const union event *ev); | 74 gridmenu_handle(struct gridmenu *, const union event *); |
156 | 75 |
157 /** | |
158 * Draw the menu. | |
159 * | |
160 * \pre menu != NULL && menu->nrows > 0 && menu->ncols > 0 | |
161 * \param menu the menu to draw | |
162 */ | |
163 void | 76 void |
164 gridmenu_draw(const struct gridmenu *menu); | 77 gridmenu_draw(const struct gridmenu *); |
165 | 78 |
166 /** | |
167 * Close internal resources. | |
168 * | |
169 * \pre menu != NULL | |
170 * \param menu the menu to close | |
171 */ | |
172 void | 79 void |
173 gridmenu_finish(struct gridmenu *menu); | 80 gridmenu_finish(struct gridmenu *); |
174 | 81 |
175 CORE_END_DECLS | 82 CORE_END_DECLS |
176 | 83 |
177 #endif /* !MOLKO_UI_GRIDMENU_H */ | 84 #endif /* !MOLKO_UI_GRIDMENU_H */ |