comparison src/libmlk-ui/ui/gridmenu.h @ 395:ef2fc4442ed5

ui: don't use fixed size arrays
author David Demelier <markand@malikania.fr>
date Fri, 18 Feb 2022 16:02:01 +0100
parents 460c78706989
children 14ce7c4871e3
comparison
equal deleted inserted replaced
394:8273c40a5691 395:ef2fc4442ed5
20 #define MLK_UI_GRIDMENU_H 20 #define MLK_UI_GRIDMENU_H
21 21
22 #include <stddef.h> 22 #include <stddef.h>
23 23
24 #include <core/core.h> 24 #include <core/core.h>
25 #include <core/texture.h>
26 25
27 #include "label.h" 26 #include "label.h"
28
29 #define GRIDMENU_ENTRY_MAX (256)
30 27
31 struct theme; 28 struct theme;
32 29
33 union event; 30 union event;
34
35 enum gridmenu_state {
36 GRIDMENU_STATE_NONE,
37 GRIDMENU_STATE_ACTIVATED
38 };
39
40 struct gridmenu_texture {
41 int rely;
42 unsigned int relh;
43 unsigned int eltw;
44 unsigned int elth;
45 unsigned int spacev;
46 unsigned int spaceh;
47 struct texture texture;
48 struct label labels[GRIDMENU_ENTRY_MAX];
49 };
50 31
51 struct gridmenu { 32 struct gridmenu {
52 int x; 33 int x;
53 int y; 34 int y;
54 unsigned int w; 35 unsigned int w;
55 unsigned int h; 36 unsigned int h;
56 enum gridmenu_state state;
57 size_t selected; 37 size_t selected;
58 const struct theme *theme; 38 const struct theme *theme;
59 const char *menu[GRIDMENU_ENTRY_MAX]; 39 const char * const *items;
40 size_t itemsz;
60 unsigned int nrows; 41 unsigned int nrows;
61 unsigned int ncols; 42 unsigned int ncols;
62 struct gridmenu_texture tex; 43
44 /* Private fields. */
45 unsigned int eltw; /* maximum entry label width */
46 unsigned int elth; /* maximum entry label height */
47 unsigned int spacew; /* space between element horizontally */
48 unsigned int spaceh; /* and vertically */
63 }; 49 };
64 50
65 CORE_BEGIN_DECLS 51 CORE_BEGIN_DECLS
66 52
67 void 53 void
68 gridmenu_reset(struct gridmenu *); 54 gridmenu_init(struct gridmenu *, unsigned int, unsigned int, const char * const *, size_t);
69 55
70 void 56 void
71 gridmenu_repaint(struct gridmenu *); 57 gridmenu_resize(struct gridmenu *, int, int, unsigned int, unsigned int);
72 58
73 void 59 int
74 gridmenu_handle(struct gridmenu *, const union event *); 60 gridmenu_handle(struct gridmenu *, const union event *);
75 61
76 void 62 void
77 gridmenu_draw(const struct gridmenu *); 63 gridmenu_draw(const struct gridmenu *);
78 64
79 void
80 gridmenu_finish(struct gridmenu *);
81
82 CORE_END_DECLS 65 CORE_END_DECLS
83 66
84 #endif /* !MLK_UI_GRIDMENU_H */ 67 #endif /* !MLK_UI_GRIDMENU_H */