comparison libmlk-ui/mlk/ui/gridmenu.c @ 493:fce3b3c4b496

ui: label -> mlk_label
author David Demelier <markand@malikania.fr>
date Tue, 28 Feb 2023 13:26:53 +0100
parents c7b18475f640
children 2af25db99273
comparison
equal deleted inserted replaced
492:c7b18475f640 493:fce3b3c4b496
50 50
51 static void 51 static void
52 geometry(struct mlk_gridmenu *menu) 52 geometry(struct mlk_gridmenu *menu)
53 { 53 {
54 const struct theme *theme = THEME(menu); 54 const struct theme *theme = THEME(menu);
55 struct label label = { 55 struct mlk_label label = {
56 .theme = theme, 56 .theme = theme,
57 .flags = LABEL_FLAGS_SHADOW 57 .flags = MLK_LABEL_FLAGS_SHADOW
58 }; 58 };
59 unsigned int reqw = 0, reqh = 0, lw, lh; 59 unsigned int reqw = 0, reqh = 0, lw, lh;
60 60
61 /* Compute which item has the bigger width/height to create a spacing. */ 61 /* Compute which item has the bigger width/height to create a spacing. */
62 menu->eltw = menu->elth = 0; 62 menu->eltw = menu->elth = 0;
65 for (size_t i = 0; i < menu->itemsz; ++i) { 65 for (size_t i = 0; i < menu->itemsz; ++i) {
66 if (!(label.text = menu->items[i])) 66 if (!(label.text = menu->items[i]))
67 continue; 67 continue;
68 68
69 69
70 label_query(&label, &lw, &lh); 70 mlk_label_query(&label, &lw, &lh);
71 71
72 menu->eltw = fmax(menu->eltw, lw); 72 menu->eltw = fmax(menu->eltw, lw);
73 menu->elth = fmax(menu->elth, lh); 73 menu->elth = fmax(menu->elth, lh);
74 } 74 }
75 75
114 114
115 static void 115 static void
116 draw_labels(const struct mlk_gridmenu *menu) 116 draw_labels(const struct mlk_gridmenu *menu)
117 { 117 {
118 size_t pagesz, pagenr, item, c = 0, r = 0; 118 size_t pagesz, pagenr, item, c = 0, r = 0;
119 struct label label = {0}; 119 struct mlk_label label = {0};
120 const struct theme *theme = THEME(menu); 120 const struct theme *theme = THEME(menu);
121 121
122 label.theme = theme; 122 label.theme = theme;
123 label.flags = LABEL_FLAGS_SHADOW; 123 label.flags = MLK_LABEL_FLAGS_SHADOW;
124 124
125 /* 125 /*
126 * Select the first top-left column based on the current selection and 126 * Select the first top-left column based on the current selection and
127 * the number of rows/columns. 127 * the number of rows/columns.
128 */ 128 */
138 label.text = menu->items[item]; 138 label.text = menu->items[item];
139 label.x = menu->x + theme->padding + (c * menu->eltw) + (c * menu->spacew); 139 label.x = menu->x + theme->padding + (c * menu->eltw) + (c * menu->spacew);
140 label.y = menu->y + theme->padding + (r * menu->elth) + (r * menu->spaceh); 140 label.y = menu->y + theme->padding + (r * menu->elth) + (r * menu->spaceh);
141 141
142 if (i == menu->selected % pagesz) 142 if (i == menu->selected % pagesz)
143 label.flags |= LABEL_FLAGS_SELECTED; 143 label.flags |= MLK_LABEL_FLAGS_SELECTED;
144 else 144 else
145 label.flags &= ~(LABEL_FLAGS_SELECTED); 145 label.flags &= ~(MLK_LABEL_FLAGS_SELECTED);
146 146
147 label_draw(&label); 147 mlk_label_draw(&label);
148 148
149 if (++c >= menu->ncols) { 149 if (++c >= menu->ncols) {
150 ++r; 150 ++r;
151 c = 0; 151 c = 0;
152 } 152 }