blob: 8db6a2b2f4d0a95d90d5110a4d1a4d34da009a81 [file] [log] [blame]
Simon Glass9f513932023-01-06 08:52:38 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Implementation of a menu in a scene
4 *
5 * Copyright 2022 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
Simon Glassfe4c1e22023-06-01 10:22:43 -06009#define LOG_CATEGORY LOGC_EXPO
Simon Glass9f513932023-01-06 08:52:38 -060010
Simon Glass9f513932023-01-06 08:52:38 -060011#include <dm.h>
12#include <expo.h>
13#include <malloc.h>
14#include <mapmem.h>
15#include <menu.h>
16#include <video.h>
17#include <video_console.h>
18#include <linux/input.h>
19#include "scene_internal.h"
20
21static void scene_menuitem_destroy(struct scene_menitem *item)
22{
23 free(item->name);
24 free(item);
25}
26
27void scene_menu_destroy(struct scene_obj_menu *menu)
28{
29 struct scene_menitem *item, *next;
30
31 list_for_each_entry_safe(item, next, &menu->item_head, sibling)
32 scene_menuitem_destroy(item);
33}
34
Simon Glass5fd4f782023-08-14 16:40:32 -060035struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu,
36 int id)
Simon Glassc55eeba2023-06-01 10:22:54 -060037{
38 struct scene_menitem *item;
39
40 list_for_each_entry(item, &menu->item_head, sibling) {
41 if (item->id == id)
42 return item;
43 }
44
45 return NULL;
46}
47
Simon Glass4462fa32023-08-14 16:40:38 -060048struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu,
49 uint seq)
50{
51 struct scene_menitem *item;
52 uint i;
53
54 i = 0;
55 list_for_each_entry(item, &menu->item_head, sibling) {
56 if (i == seq)
57 return item;
58 i++;
59 }
60
61 return NULL;
62}
63
Simon Glass100389f2024-10-14 16:31:58 -060064struct scene_menitem *scene_menuitem_find_val(const struct scene_obj_menu *menu,
65 int val)
66{
67 struct scene_menitem *item;
68 uint i;
69
70 i = 0;
71 list_for_each_entry(item, &menu->item_head, sibling) {
Simon Glass6f3e87a2024-10-14 16:32:00 -060072 if (item->value == INT_MAX ? val == i : item->value == val)
Simon Glass100389f2024-10-14 16:31:58 -060073 return item;
74 i++;
75 }
76
77 return NULL;
78}
79
Simon Glassc55eeba2023-06-01 10:22:54 -060080/**
81 * update_pointers() - Update the pointer object and handle highlights
82 *
83 * @menu: Menu to update
84 * @id: ID of menu item to select/deselect
85 * @point: true if @id is being selected, false if it is being deselected
86 */
87static int update_pointers(struct scene_obj_menu *menu, uint id, bool point)
88{
89 struct scene *scn = menu->obj.scene;
Simon Glass2d857262025-05-02 08:46:50 -060090 const bool stack = scn->expo->show_highlight;
Simon Glassc55eeba2023-06-01 10:22:54 -060091 const struct scene_menitem *item;
92 int ret;
93
94 item = scene_menuitem_find(menu, id);
95 if (!item)
96 return log_msg_ret("itm", -ENOENT);
97
98 /* adjust the pointer object to point to the selected item */
99 if (menu->pointer_id && item && point) {
100 struct scene_obj *label;
101
102 label = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE);
103
104 ret = scene_obj_set_pos(scn, menu->pointer_id,
Simon Glassbc3a15f2025-05-02 08:46:31 -0600105 menu->obj.bbox.x0 + 200, label->bbox.y0);
Simon Glassc55eeba2023-06-01 10:22:54 -0600106 if (ret < 0)
107 return log_msg_ret("ptr", ret);
108 }
109
Simon Glassd353b752023-06-01 10:22:55 -0600110 if (stack) {
Simon Glass2d857262025-05-02 08:46:50 -0600111 uint id;
112 int val;
113
Simon Glassd353b752023-06-01 10:22:55 -0600114 point &= scn->highlight_id == menu->obj.id;
Simon Glass2d857262025-05-02 08:46:50 -0600115 val = point ? SCENEOF_POINT : 0;
116 id = item->desc_id;
117 if (!id)
118 id = item->label_id;
119 if (!id)
120 id = item->key_id;
121 scene_obj_flag_clrset(scn, id, SCENEOF_POINT, val);
Simon Glassd353b752023-06-01 10:22:55 -0600122 }
123
Simon Glassc55eeba2023-06-01 10:22:54 -0600124 return 0;
125}
126
Simon Glass9f513932023-01-06 08:52:38 -0600127/**
128 * menu_point_to_item() - Point to a particular menu item
129 *
130 * Sets the currently pointed-to / highlighted menu item
131 */
Simon Glassbe04b962025-05-02 08:46:24 -0600132static int menu_point_to_item(struct scene_obj_menu *menu, uint item_id)
Simon Glass9f513932023-01-06 08:52:38 -0600133{
Simon Glassbe04b962025-05-02 08:46:24 -0600134 int ret;
135
136 if (menu->cur_item_id) {
137 ret = update_pointers(menu, menu->cur_item_id, false);
138 if (ret)
139 return log_msg_ret("mpi", ret);
140 }
Simon Glass9f513932023-01-06 08:52:38 -0600141 menu->cur_item_id = item_id;
Simon Glassbe04b962025-05-02 08:46:24 -0600142 ret = update_pointers(menu, item_id, true);
143 if (ret)
144 return log_msg_ret("mpu", ret);
145
146 return 0;
Simon Glass9f513932023-01-06 08:52:38 -0600147}
148
Simon Glassf0994692023-10-01 19:13:29 -0600149void scene_menu_calc_bbox(struct scene_obj_menu *menu,
Simon Glass96910ef2025-05-02 08:46:34 -0600150 struct vidconsole_bbox *bbox)
Simon Glass7a960052023-06-01 10:22:52 -0600151{
Simon Glass86f1ac52023-06-01 10:23:00 -0600152 const struct expo_theme *theme = &menu->obj.scene->expo->theme;
Simon Glass7a960052023-06-01 10:22:52 -0600153 const struct scene_menitem *item;
Simon Glass96910ef2025-05-02 08:46:34 -0600154 int inset = theme->menu_inset;
155 int i;
Simon Glass7a960052023-06-01 10:22:52 -0600156
Simon Glass96910ef2025-05-02 08:46:34 -0600157 for (i = 0; i < SCENEBB_count; i++)
158 bbox[i].valid = false;
Simon Glass7a960052023-06-01 10:22:52 -0600159
Simon Glass96910ef2025-05-02 08:46:34 -0600160 scene_bbox_union(menu->obj.scene, menu->title_id, 0,
161 &bbox[SCENEBB_all]);
Simon Glass7a960052023-06-01 10:22:52 -0600162
163 list_for_each_entry(item, &menu->item_head, sibling) {
Simon Glass96910ef2025-05-02 08:46:34 -0600164 struct vidconsole_bbox local;
Simon Glass7a960052023-06-01 10:22:52 -0600165
Simon Glass96910ef2025-05-02 08:46:34 -0600166 local.valid = false;
167 scene_bbox_union(menu->obj.scene, item->label_id, inset,
168 &local);
169 scene_bbox_union(menu->obj.scene, item->key_id, 0, &local);
170 scene_bbox_union(menu->obj.scene, item->desc_id, 0, &local);
171 scene_bbox_union(menu->obj.scene, item->preview_id, 0, &local);
172
173 scene_bbox_join(&local, 0, &bbox[SCENEBB_all]);
174
175 /* Get the bounding box of all individual fields */
176 scene_bbox_union(menu->obj.scene, item->label_id, inset,
177 &bbox[SCENEBB_label]);
178 scene_bbox_union(menu->obj.scene, item->key_id, inset,
179 &bbox[SCENEBB_key]);
180 scene_bbox_union(menu->obj.scene, item->desc_id, inset,
181 &bbox[SCENEBB_desc]);
182
183 if (menu->cur_item_id == item->id)
184 scene_bbox_join(&local, 0, &bbox[SCENEBB_curitem]);
Simon Glass7a960052023-06-01 10:22:52 -0600185 }
Simon Glass86f1ac52023-06-01 10:23:00 -0600186
187 /*
Simon Glass96910ef2025-05-02 08:46:34 -0600188 * subtract the final menuitem's gap to keep the inset the same top and
189 * bottom
Simon Glass86f1ac52023-06-01 10:23:00 -0600190 */
Simon Glass96910ef2025-05-02 08:46:34 -0600191 bbox[SCENEBB_label].y1 -= theme->menuitem_gap_y;
Simon Glass7a960052023-06-01 10:22:52 -0600192}
193
194int scene_menu_calc_dims(struct scene_obj_menu *menu)
195{
Simon Glass96910ef2025-05-02 08:46:34 -0600196 struct vidconsole_bbox bbox[SCENEBB_count], *cur;
Simon Glass7a960052023-06-01 10:22:52 -0600197 const struct scene_menitem *item;
198
Simon Glass96910ef2025-05-02 08:46:34 -0600199 scene_menu_calc_bbox(menu, bbox);
Simon Glass7a960052023-06-01 10:22:52 -0600200
Simon Glass43bfbb22025-05-02 08:46:36 -0600201 /* Make all field types the same width */
202 list_for_each_entry(item, &menu->item_head, sibling) {
203 cur = &bbox[SCENEBB_label];
204 if (cur->valid)
205 scene_obj_set_width(menu->obj.scene, item->label_id,
206 cur->x1 - cur->x0);
207 cur = &bbox[SCENEBB_key];
208 if (cur->valid)
209 scene_obj_set_width(menu->obj.scene, item->key_id,
210 cur->x1 - cur->x0);
211 cur = &bbox[SCENEBB_desc];
212 if (cur->valid)
213 scene_obj_set_width(menu->obj.scene, item->desc_id,
214 cur->x1 - cur->x0);
Simon Glass7a960052023-06-01 10:22:52 -0600215 }
216
Simon Glass96910ef2025-05-02 08:46:34 -0600217 cur = &bbox[SCENEBB_all];
218 if (cur->valid) {
219 menu->obj.dims.x = cur->x1 - cur->x0;
220 menu->obj.dims.y = cur->y1 - cur->y0;
221
222 menu->obj.bbox.x1 = cur->x1;
223 menu->obj.bbox.y1 = cur->y1;
Simon Glass7a960052023-06-01 10:22:52 -0600224 }
225
226 return 0;
227}
228
Simon Glass377f18e2024-10-14 16:31:55 -0600229int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr,
230 struct scene_obj_menu *menu)
Simon Glass9f513932023-01-06 08:52:38 -0600231{
Simon Glassd353b752023-06-01 10:22:55 -0600232 const bool open = menu->obj.flags & SCENEOF_OPEN;
233 struct expo *exp = scn->expo;
234 const bool stack = exp->popup;
Simon Glass86f1ac52023-06-01 10:23:00 -0600235 const struct expo_theme *theme = &exp->theme;
Simon Glass9f513932023-01-06 08:52:38 -0600236 struct scene_menitem *item;
Simon Glassc55eeba2023-06-01 10:22:54 -0600237 uint sel_id;
Simon Glassd353b752023-06-01 10:22:55 -0600238 int x, y;
Simon Glass9f513932023-01-06 08:52:38 -0600239 int ret;
240
Simon Glassbc3a15f2025-05-02 08:46:31 -0600241 x = menu->obj.bbox.x0;
242 y = menu->obj.bbox.y0;
Simon Glass9f513932023-01-06 08:52:38 -0600243 if (menu->title_id) {
Simon Glass377f18e2024-10-14 16:31:55 -0600244 int width;
245
Simon Glassbc3a15f2025-05-02 08:46:31 -0600246 ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.bbox.x0, y);
Simon Glass9f513932023-01-06 08:52:38 -0600247 if (ret < 0)
248 return log_msg_ret("tit", ret);
249
Simon Glass377f18e2024-10-14 16:31:55 -0600250 ret = scene_obj_get_hw(scn, menu->title_id, &width);
Simon Glass9f513932023-01-06 08:52:38 -0600251 if (ret < 0)
252 return log_msg_ret("hei", ret);
253
Simon Glassd353b752023-06-01 10:22:55 -0600254 if (stack)
Simon Glass377f18e2024-10-14 16:31:55 -0600255 x += arr->label_width + theme->menu_title_margin_x;
Simon Glassd353b752023-06-01 10:22:55 -0600256 else
257 y += ret * 2;
Simon Glass9f513932023-01-06 08:52:38 -0600258 }
259
260 /*
261 * Currently everything is hard-coded to particular columns so this
262 * won't work on small displays and looks strange if the font size is
263 * small. This can be updated once text measuring is supported in
264 * vidconsole
265 */
Simon Glassc55eeba2023-06-01 10:22:54 -0600266 sel_id = menu->cur_item_id;
Simon Glass9f513932023-01-06 08:52:38 -0600267 list_for_each_entry(item, &menu->item_head, sibling) {
Simon Glassd353b752023-06-01 10:22:55 -0600268 bool selected;
Simon Glass9f513932023-01-06 08:52:38 -0600269 int height;
270
Simon Glassd353b752023-06-01 10:22:55 -0600271 ret = scene_obj_get_hw(scn, item->label_id, NULL);
Simon Glass9f513932023-01-06 08:52:38 -0600272 if (ret < 0)
273 return log_msg_ret("get", ret);
274 height = ret;
275
276 if (item->flags & SCENEMIF_GAP_BEFORE)
277 y += height;
278
279 /* select an item if not done already */
Simon Glassc55eeba2023-06-01 10:22:54 -0600280 if (!sel_id)
281 sel_id = item->id;
Simon Glass9f513932023-01-06 08:52:38 -0600282
Simon Glassd353b752023-06-01 10:22:55 -0600283 selected = sel_id == item->id;
284
Simon Glass9f513932023-01-06 08:52:38 -0600285 /*
286 * Put the label on the left, then leave a space for the
287 * pointer, then the key and the description
288 */
Simon Glass86f1ac52023-06-01 10:23:00 -0600289 ret = scene_obj_set_pos(scn, item->label_id,
290 x + theme->menu_inset, y);
Simon Glass9f513932023-01-06 08:52:38 -0600291 if (ret < 0)
Simon Glassd353b752023-06-01 10:22:55 -0600292 return log_msg_ret("nam", ret);
293 scene_obj_set_hide(scn, item->label_id,
294 stack && !open && !selected);
Simon Glass9f513932023-01-06 08:52:38 -0600295
Simon Glassd353b752023-06-01 10:22:55 -0600296 if (item->key_id) {
297 ret = scene_obj_set_pos(scn, item->key_id, x + 230, y);
298 if (ret < 0)
299 return log_msg_ret("key", ret);
300 }
Simon Glass9f513932023-01-06 08:52:38 -0600301
Simon Glassd353b752023-06-01 10:22:55 -0600302 if (item->desc_id) {
303 ret = scene_obj_set_pos(scn, item->desc_id, x + 280, y);
304 if (ret < 0)
305 return log_msg_ret("des", ret);
306 }
Simon Glass9f513932023-01-06 08:52:38 -0600307
308 if (item->preview_id) {
309 bool hide;
310
311 /*
312 * put all previews on top of each other, on the right
313 * size of the display
314 */
315 ret = scene_obj_set_pos(scn, item->preview_id, -4, y);
316 if (ret < 0)
317 return log_msg_ret("prev", ret);
318
319 hide = menu->cur_item_id != item->id;
320 ret = scene_obj_set_hide(scn, item->preview_id, hide);
321 if (ret < 0)
322 return log_msg_ret("hid", ret);
323 }
324
Simon Glassd353b752023-06-01 10:22:55 -0600325 if (!stack || open)
Simon Glass86f1ac52023-06-01 10:23:00 -0600326 y += height + theme->menuitem_gap_y;
Simon Glass9f513932023-01-06 08:52:38 -0600327 }
328
Simon Glassc55eeba2023-06-01 10:22:54 -0600329 if (sel_id)
330 menu_point_to_item(menu, sel_id);
Simon Glassebec4972025-05-02 08:46:33 -0600331 menu->obj.bbox.x1 = menu->obj.bbox.x0 + menu->obj.dims.x;
332 menu->obj.bbox.y1 = menu->obj.bbox.y0 + menu->obj.dims.y;
333 menu->obj.flags |= SCENEOF_SIZE_VALID;
Simon Glass9f513932023-01-06 08:52:38 -0600334
335 return 0;
336}
337
338int scene_menu(struct scene *scn, const char *name, uint id,
339 struct scene_obj_menu **menup)
340{
341 struct scene_obj_menu *menu;
342 int ret;
343
344 ret = scene_obj_add(scn, name, id, SCENEOBJT_MENU,
345 sizeof(struct scene_obj_menu),
346 (struct scene_obj **)&menu);
347 if (ret < 0)
348 return log_msg_ret("obj", -ENOMEM);
349
350 if (menup)
351 *menup = menu;
352 INIT_LIST_HEAD(&menu->item_head);
353
Simon Glass9f513932023-01-06 08:52:38 -0600354 return menu->obj.id;
355}
356
357static struct scene_menitem *scene_menu_find_key(struct scene *scn,
358 struct scene_obj_menu *menu,
359 int key)
360{
361 struct scene_menitem *item;
362
363 list_for_each_entry(item, &menu->item_head, sibling) {
364 if (item->key_id) {
365 struct scene_obj_txt *txt;
366 const char *str;
367
368 txt = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT);
369 if (txt) {
Simon Glass9ef02aa2025-05-02 08:46:37 -0600370 str = expo_get_str(scn->expo, txt->gen.str_id);
Simon Glass9f513932023-01-06 08:52:38 -0600371 if (str && *str == key)
372 return item;
373 }
374 }
375 }
376
377 return NULL;
378}
379
380int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
381 struct expo_action *event)
382{
Simon Glassf0e1e8c2023-06-01 10:22:59 -0600383 const bool open = menu->obj.flags & SCENEOF_OPEN;
Simon Glass9f513932023-01-06 08:52:38 -0600384 struct scene_menitem *item, *cur, *key_item;
385
386 cur = NULL;
387 key_item = NULL;
388
389 if (!list_empty(&menu->item_head)) {
390 list_for_each_entry(item, &menu->item_head, sibling) {
391 /* select an item if not done already */
392 if (menu->cur_item_id == item->id) {
393 cur = item;
394 break;
395 }
396 }
397 }
398
399 if (!cur)
400 return -ENOTTY;
401
402 switch (key) {
403 case BKEY_UP:
404 if (item != list_first_entry(&menu->item_head,
405 struct scene_menitem, sibling)) {
406 item = list_entry(item->sibling.prev,
407 struct scene_menitem, sibling);
Simon Glass719a3c62023-06-01 10:22:56 -0600408 event->type = EXPOACT_POINT_ITEM;
Simon Glass9f513932023-01-06 08:52:38 -0600409 event->select.id = item->id;
410 log_debug("up to item %d\n", event->select.id);
411 }
412 break;
413 case BKEY_DOWN:
414 if (!list_is_last(&item->sibling, &menu->item_head)) {
415 item = list_entry(item->sibling.next,
416 struct scene_menitem, sibling);
Simon Glass719a3c62023-06-01 10:22:56 -0600417 event->type = EXPOACT_POINT_ITEM;
Simon Glass9f513932023-01-06 08:52:38 -0600418 event->select.id = item->id;
419 log_debug("down to item %d\n", event->select.id);
420 }
421 break;
422 case BKEY_SELECT:
423 event->type = EXPOACT_SELECT;
424 event->select.id = item->id;
425 log_debug("select item %d\n", event->select.id);
426 break;
427 case BKEY_QUIT:
Simon Glassf0e1e8c2023-06-01 10:22:59 -0600428 if (scn->expo->popup && open) {
429 event->type = EXPOACT_CLOSE;
430 event->select.id = menu->obj.id;
431 } else {
432 event->type = EXPOACT_QUIT;
433 log_debug("menu quit\n");
434 }
Simon Glass9f513932023-01-06 08:52:38 -0600435 break;
436 case '0'...'9':
437 key_item = scene_menu_find_key(scn, menu, key);
438 if (key_item) {
439 event->type = EXPOACT_SELECT;
440 event->select.id = key_item->id;
441 }
442 break;
443 }
444
Simon Glass9f513932023-01-06 08:52:38 -0600445 return 0;
446}
447
448int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
449 uint key_id, uint label_id, uint desc_id, uint preview_id,
450 uint flags, struct scene_menitem **itemp)
451{
452 struct scene_obj_menu *menu;
453 struct scene_menitem *item;
Simon Glass9f513932023-01-06 08:52:38 -0600454
455 menu = scene_obj_find(scn, menu_id, SCENEOBJT_MENU);
456 if (!menu)
457 return log_msg_ret("find", -ENOENT);
458
459 /* Check that the text ID is valid */
Simon Glassd353b752023-06-01 10:22:55 -0600460 if (!scene_obj_find(scn, label_id, SCENEOBJT_TEXT))
Simon Glass9f513932023-01-06 08:52:38 -0600461 return log_msg_ret("txt", -EINVAL);
462
Dan Carpenter463be542023-07-31 17:08:29 +0300463 item = calloc(1, sizeof(struct scene_menitem));
Simon Glass9f513932023-01-06 08:52:38 -0600464 if (!item)
465 return log_msg_ret("item", -ENOMEM);
466 item->name = strdup(name);
467 if (!item->name) {
468 free(item);
469 return log_msg_ret("name", -ENOMEM);
470 }
471
472 item->id = resolve_id(scn->expo, id);
473 item->key_id = key_id;
474 item->label_id = label_id;
475 item->desc_id = desc_id;
476 item->preview_id = preview_id;
477 item->flags = flags;
Simon Glass100389f2024-10-14 16:31:58 -0600478 item->value = INT_MAX;
Simon Glass9f513932023-01-06 08:52:38 -0600479 list_add_tail(&item->sibling, &menu->item_head);
480
Simon Glass9f513932023-01-06 08:52:38 -0600481 if (itemp)
482 *itemp = item;
483
484 return item->id;
485}
486
487int scene_menu_set_title(struct scene *scn, uint id, uint title_id)
488{
489 struct scene_obj_menu *menu;
490 struct scene_obj_txt *txt;
491
492 menu = scene_obj_find(scn, id, SCENEOBJT_MENU);
493 if (!menu)
494 return log_msg_ret("menu", -ENOENT);
495
496 /* Check that the ID is valid */
497 if (title_id) {
498 txt = scene_obj_find(scn, title_id, SCENEOBJT_TEXT);
499 if (!txt)
500 return log_msg_ret("txt", -EINVAL);
501 }
502
503 menu->title_id = title_id;
504
505 return 0;
506}
507
508int scene_menu_set_pointer(struct scene *scn, uint id, uint pointer_id)
509{
510 struct scene_obj_menu *menu;
511 struct scene_obj *obj;
512
513 menu = scene_obj_find(scn, id, SCENEOBJT_MENU);
514 if (!menu)
515 return log_msg_ret("menu", -ENOENT);
516
517 /* Check that the ID is valid */
518 if (pointer_id) {
519 obj = scene_obj_find(scn, pointer_id, SCENEOBJT_NONE);
520 if (!obj)
521 return log_msg_ret("obj", -EINVAL);
522 }
523
524 menu->pointer_id = pointer_id;
525
526 return 0;
527}
528
Simon Glassbe04b962025-05-02 08:46:24 -0600529int scene_menu_select_item(struct scene *scn, uint id, uint cur_item_id)
530{
531 struct scene_obj_menu *menu;
532 int ret;
533
534 menu = scene_obj_find(scn, id, SCENEOBJT_MENU);
535 if (!menu)
536 return log_msg_ret("menu", -ENOENT);
537
538 ret = menu_point_to_item(menu, cur_item_id);
539 if (ret)
540 return log_msg_ret("msi", ret);
541
542 return 0;
543}
544
545int scene_menu_get_cur_item(struct scene *scn, uint id)
546{
547 struct scene_obj_menu *menu;
548
549 menu = scene_obj_find(scn, id, SCENEOBJT_MENU);
550 if (!menu)
551 return log_msg_ret("menu", -ENOENT);
552
553 return menu->cur_item_id;
554}
555
Simon Glass9f513932023-01-06 08:52:38 -0600556int scene_menu_display(struct scene_obj_menu *menu)
557{
558 struct scene *scn = menu->obj.scene;
559 struct scene_obj_txt *pointer;
560 struct expo *exp = scn->expo;
561 struct scene_menitem *item;
562 const char *pstr;
563
564 printf("U-Boot : Boot Menu\n\n");
565 if (menu->title_id) {
566 struct scene_obj_txt *txt;
567 const char *str;
568
569 txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_TEXT);
570 if (!txt)
571 return log_msg_ret("txt", -EINVAL);
572
Simon Glass9ef02aa2025-05-02 08:46:37 -0600573 str = expo_get_str(exp, txt->gen.str_id);
Simon Glass9f513932023-01-06 08:52:38 -0600574 printf("%s\n\n", str);
575 }
576
577 if (list_empty(&menu->item_head))
578 return 0;
579
580 pointer = scene_obj_find(scn, menu->pointer_id, SCENEOBJT_TEXT);
Simon Glass9ef02aa2025-05-02 08:46:37 -0600581 pstr = expo_get_str(scn->expo, pointer->gen.str_id);
Simon Glass9f513932023-01-06 08:52:38 -0600582
583 list_for_each_entry(item, &menu->item_head, sibling) {
584 struct scene_obj_txt *key = NULL, *label = NULL;
585 struct scene_obj_txt *desc = NULL;
586 const char *kstr = NULL, *lstr = NULL, *dstr = NULL;
587
588 key = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT);
589 if (key)
Simon Glass9ef02aa2025-05-02 08:46:37 -0600590 kstr = expo_get_str(exp, key->gen.str_id);
Simon Glass9f513932023-01-06 08:52:38 -0600591
592 label = scene_obj_find(scn, item->label_id, SCENEOBJT_TEXT);
593 if (label)
Simon Glass9ef02aa2025-05-02 08:46:37 -0600594 lstr = expo_get_str(exp, label->gen.str_id);
Simon Glass9f513932023-01-06 08:52:38 -0600595
596 desc = scene_obj_find(scn, item->desc_id, SCENEOBJT_TEXT);
597 if (desc)
Simon Glass9ef02aa2025-05-02 08:46:37 -0600598 dstr = expo_get_str(exp, desc->gen.str_id);
Simon Glass9f513932023-01-06 08:52:38 -0600599
600 printf("%3s %3s %-10s %s\n",
601 pointer && menu->cur_item_id == item->id ? pstr : "",
602 kstr, lstr, dstr);
603 }
604
605 return -ENOTSUPP;
606}
Simon Glass01922ec2023-06-01 10:22:57 -0600607
Simon Glass12f57732023-06-01 10:22:58 -0600608int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu)
609{
610 struct scene_menitem *item;
611
612 scene_render_deps(scn, menu->title_id);
613 scene_render_deps(scn, menu->cur_item_id);
614 scene_render_deps(scn, menu->pointer_id);
615
616 list_for_each_entry(item, &menu->item_head, sibling) {
617 scene_render_deps(scn, item->key_id);
618 scene_render_deps(scn, item->label_id);
619 scene_render_deps(scn, item->desc_id);
620 }
621
622 return 0;
623}