]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
expo: Provide access to the current menu item
authorSimon Glass <sjg@chromium.org>
Fri, 2 May 2025 14:46:24 +0000 (08:46 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 30 May 2025 08:49:32 +0000 (09:49 +0100)
Add functions to allow a caller to find out the current menu item and to
select a different one.

Update the event handling so that an attempt to change the current item
(e.g. by pressing the up-arrow key) is reported to the caller, since
this may be used to cancel an autoboot timeout.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/scene_menu.c
include/expo.h
test/boot/expo.c

index 17150af145dcd4ea2dbcbf7e0e63c4c2f7af64de..06d7e9fc913a2e96df0fa27deb7cca01436b3e1d 100644 (file)
@@ -121,12 +121,21 @@ static int update_pointers(struct scene_obj_menu *menu, uint id, bool point)
  *
  * Sets the currently pointed-to / highlighted menu item
  */
-static void menu_point_to_item(struct scene_obj_menu *menu, uint item_id)
+static int menu_point_to_item(struct scene_obj_menu *menu, uint item_id)
 {
-       if (menu->cur_item_id)
-               update_pointers(menu, menu->cur_item_id, false);
+       int ret;
+
+       if (menu->cur_item_id) {
+               ret = update_pointers(menu, menu->cur_item_id, false);
+               if (ret)
+                       return log_msg_ret("mpi", ret);
+       }
        menu->cur_item_id = item_id;
-       update_pointers(menu, item_id, true);
+       ret = update_pointers(menu, item_id, true);
+       if (ret)
+               return log_msg_ret("mpu", ret);
+
+       return 0;
 }
 
 void scene_menu_calc_bbox(struct scene_obj_menu *menu,
@@ -483,6 +492,33 @@ int scene_menu_set_pointer(struct scene *scn, uint id, uint pointer_id)
        return 0;
 }
 
+int scene_menu_select_item(struct scene *scn, uint id, uint cur_item_id)
+{
+       struct scene_obj_menu *menu;
+       int ret;
+
+       menu = scene_obj_find(scn, id, SCENEOBJT_MENU);
+       if (!menu)
+               return log_msg_ret("menu", -ENOENT);
+
+       ret = menu_point_to_item(menu, cur_item_id);
+       if (ret)
+               return log_msg_ret("msi", ret);
+
+       return 0;
+}
+
+int scene_menu_get_cur_item(struct scene *scn, uint id)
+{
+       struct scene_obj_menu *menu;
+
+       menu = scene_obj_find(scn, id, SCENEOBJT_MENU);
+       if (!menu)
+               return log_msg_ret("menu", -ENOENT);
+
+       return menu->cur_item_id;
+}
+
 int scene_menu_display(struct scene_obj_menu *menu)
 {
        struct scene *scn = menu->obj.scene;
index f8d44c0ea20a2f92b722fb5d63bacf6656708c69..a2b093c521d2e287897c25d50cba07a83365ae17 100644 (file)
@@ -689,6 +689,26 @@ int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
  */
 int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
 
+/**
+ * scene_menu_select_item() - move the pointer/highlight to an item
+ *
+ * @scn: Scene to update
+ * @id: ID of menu object to update
+ * @sel_id: ID of the menuitem to select
+ * Return 0 on success, -ENOENT if there was no such item
+ */
+int scene_menu_select_item(struct scene *scn, uint id, uint sel_id);
+
+/**
+ * scene_menu_get_cur_item() - get the currently pointed-to item
+ *
+ * @scn: Scene to update
+ * @id: ID of menu object to update
+ * Return ID of the current item the menu is pointing to, -ENOENT if @id is not
+ * valid, 0 if no item is pointed to
+ */
+int scene_menu_get_cur_item(struct scene *scn, uint id);
+
 /**
  * scene_obj_get_hw() - Get width and height of an object in a scene
  *
index 1d283a2ac95f90f63c0dc096d3f536688008c48a..616071ead489698a9617262cd9c479eb0da03929 100644 (file)
@@ -588,6 +588,8 @@ static int expo_render_image(struct unit_test_state *uts)
        expo_set_scene_id(exp, SCENE1);
        ut_assertok(expo_render(exp));
 
+       ut_asserteq(0, scn->highlight_id);
+
        /* move down */
        ut_assertok(expo_send_key(exp, BKEY_DOWN));
 
@@ -595,6 +597,8 @@ static int expo_render_image(struct unit_test_state *uts)
 
        ut_asserteq(EXPOACT_POINT_ITEM, act.type);
        ut_asserteq(ITEM2, act.select.id);
+       ut_assertok(scene_menu_select_item(scn, OBJ_MENU, act.select.id));
+       ut_asserteq(ITEM2, scene_menu_get_cur_item(scn, OBJ_MENU));
        ut_assertok(expo_render(exp));
 
        /* make sure only the preview for the second item is shown */