comparison examples/example-gridmenu/example-gridmenu.c @ 608:2527b000aaa5

ui: do the same with gridmenu
author David Demelier <markand@malikania.fr>
date Fri, 11 Aug 2023 19:45:00 +0200
parents c7664b679a95
children d97674d33764
comparison
equal deleted inserted replaced
607:8444f83d48af 608:2527b000aaa5
30 30
31 #include <mlk/ui/align.h> 31 #include <mlk/ui/align.h>
32 #include <mlk/ui/frame.h> 32 #include <mlk/ui/frame.h>
33 #include <mlk/ui/gridmenu.h> 33 #include <mlk/ui/gridmenu.h>
34 #include <mlk/ui/label.h> 34 #include <mlk/ui/label.h>
35 #include <mlk/ui/style.h>
35 #include <mlk/ui/ui.h> 36 #include <mlk/ui/ui.h>
36 37
37 #include <mlk/example/example.h> 38 #include <mlk/example/example.h>
38 #include <mlk/example/glower.h> 39 #include <mlk/example/glower.h>
39 #include <mlk/example/registry.h> 40 #include <mlk/example/registry.h>
40
41 static void menu_update(struct mlk_gridmenu_delegate *, struct mlk_gridmenu *, unsigned int);
42 41
43 static const char * const items[] = { 42 static const char * const items[] = {
44 "Feu mineur", 43 "Feu mineur",
45 "Feu majeur", 44 "Feu majeur",
46 "Feu septième", 45 "Feu septième",
58 "Destruction", 57 "Destruction",
59 "Résurrection", 58 "Résurrection",
60 "Double tour" 59 "Double tour"
61 }; 60 };
62 61
62 static struct mlk_style style;
63
63 static struct mlk_frame frame = { 64 static struct mlk_frame frame = {
64 .w = 300, 65 .w = 300,
65 .h = 100 66 .h = 100,
66 }; 67 .delegate = &mlk_frame_delegate,
67 static struct mlk_gridmenu_style menu_style = {0}; 68 .style = &mlk_style
68 static struct mlk_gridmenu_delegate menu_delegate = {
69 .update = menu_update
70 }; 69 };
71 static struct mlk_gridmenu menu = { 70 static struct mlk_gridmenu menu = {
72 .nrows = 3, 71 .nrows = 3,
73 .ncols = 2, 72 .ncols = 2,
74 .items = items, 73 .items = items,
75 .itemsz = MLK_UTIL_SIZE(items), 74 .itemsz = MLK_UTIL_SIZE(items),
76 .style = &menu_style, 75 .delegate = &mlk_gridmenu_delegate,
77 .delegate = &menu_delegate 76 .style = &style,
78 }; 77 };
79 static struct mlk_glower menu_glower = { 78 static struct mlk_glower menu_glower = {
80 .start = 0x00bfa3ff, 79 .start = 0x00bfa3ff,
81 .end = 0x006b6dff, 80 .end = 0x006b6dff,
82 .delay = 20 81 .delay = 20
83 }; 82 };
84 83
85 static void 84 static void
86 menu_update(struct mlk_gridmenu_delegate *delegate, struct mlk_gridmenu *menu, unsigned int ticks) 85 update_color(unsigned int ticks)
87 { 86 {
88 (void)delegate;
89 (void)menu;
90
91 mlk_glower_update(&menu_glower, ticks); 87 mlk_glower_update(&menu_glower, ticks);
92 menu_style.selected_color = menu_glower.color; 88 style.selected.color.text = menu_glower.color;
93 } 89 }
94 90
95 static void 91 static void
96 init(void) 92 init(void)
97 { 93 {
98 if (mlk_example_init("example-gridmenu") < 0) 94 if (mlk_example_init("example-gridmenu") < 0)
99 mlk_panic(); 95 mlk_panic();
100 96
101 menu_style = mlk_gridmenu_style; 97 /* Copy style. */
98 style = mlk_style;
102 mlk_glower_init(&menu_glower); 99 mlk_glower_init(&menu_glower);
103 } 100 }
104 101
105 static void 102 static void
106 handle(struct mlk_state *st, const union mlk_event *ev) 103 handle(struct mlk_state *st, const union mlk_event *ev)
121 static void 118 static void
122 update(struct mlk_state *st, unsigned int ticks) 119 update(struct mlk_state *st, unsigned int ticks)
123 { 120 {
124 (void)st; 121 (void)st;
125 122
126 mlk_glower_update(&menu_glower, ticks); 123 update_color(ticks);
127 mlk_gridmenu_update(&menu, ticks); 124 mlk_gridmenu_update(&menu, ticks);
128 } 125 }
129 126
130 static void 127 static void
131 draw(struct mlk_state *st) 128 draw(struct mlk_state *st)