[PATCH 11/19] expo: Move menu dims calculations into scene_menu_arrange()

Simon Glass sjg at chromium.org
Mon May 5 17:42:49 CEST 2025


A menu's dimensions are currently only used for positioning the
component parts of the menu, i.e. the label, key, description and
preview.

Move the logic for this entirely into the scene_menu file and drop the
logic at the top level.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 boot/scene.c          | 12 +-------
 boot/scene_internal.h | 10 -------
 boot/scene_menu.c     | 65 ++++++++++++++++++++++++-------------------
 3 files changed, 38 insertions(+), 49 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index 258161f27ce..9c1eae3d52b 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -1043,18 +1043,8 @@ int scene_calc_dims(struct scene *scn)
 				}
 				break;
 			}
-			case SCENEOBJT_MENU: {
-				struct scene_obj_menu *menu;
-
-				if (do_menus) {
-					menu = (struct scene_obj_menu *)obj;
-
-					ret = scene_menu_calc_dims(menu);
-					if (ret)
-						return log_msg_ret("men", ret);
-				}
+			case SCENEOBJT_MENU:
 				break;
-			}
 			case SCENEOBJT_TEXTLINE: {
 				struct scene_obj_textline *tline;
 
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index f9b30caa208..cca7c18e9f5 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -259,16 +259,6 @@ int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
 int scene_textline_render_deps(struct scene *scn,
 			       struct scene_obj_textline *tline);
 
-/**
- * scene_menu_calc_dims() - Calculate the dimensions of a menu
- *
- * Updates the width and height of the menu based on its contents
- *
- * @menu: Menu to update
- * Returns 0 if OK, -ENOTSUPP if there is no graphical console
- */
-int scene_menu_calc_dims(struct scene_obj_menu *menu);
-
 /**
  * scene_iter_objs() - Iterate through all scene objects
  *
diff --git a/boot/scene_menu.c b/boot/scene_menu.c
index 3f988657e00..c2abf1e3926 100644
--- a/boot/scene_menu.c
+++ b/boot/scene_menu.c
@@ -192,45 +192,37 @@ void scene_menu_calc_bbox(struct scene_obj_menu *menu,
 	bbox[SCENEBB_label].y1 -= theme->menuitem_gap_y;
 }
 
-int scene_menu_calc_dims(struct scene_obj_menu *menu)
+static void scene_menu_calc_dims(struct scene *scn, struct scene_obj_menu *menu,
+				 struct scene_obj_dims *dims)
 {
-	struct vidconsole_bbox bbox[SCENEBB_count], *cur;
 	const struct scene_menitem *item;
 
-	scene_menu_calc_bbox(menu, bbox);
-
-	/* Make all field types the same width */
 	list_for_each_entry(item, &menu->item_head, sibling) {
-		cur = &bbox[SCENEBB_label];
-		if (cur->valid)
-			scene_obj_set_width(menu->obj.scene, item->label_id,
-					    cur->x1 - cur->x0);
-		cur = &bbox[SCENEBB_key];
-		if (cur->valid)
-			scene_obj_set_width(menu->obj.scene, item->key_id,
-					    cur->x1 - cur->x0);
-		cur = &bbox[SCENEBB_desc];
-		if (cur->valid)
-			scene_obj_set_width(menu->obj.scene, item->desc_id,
-					    cur->x1 - cur->x0);
-	}
-
-	cur = &bbox[SCENEBB_all];
-	if (cur->valid) {
-		menu->obj.dims.x = cur->x1 - cur->x0;
-		menu->obj.dims.y = cur->y1 - cur->y0;
-
-		menu->obj.bbox.x1 = cur->x1;
-		menu->obj.bbox.y1 = cur->y1;
+		struct scene_obj_dims local;
+
+		local.x = 0;
+		local.y = 0;
+		scene_dims_union(menu->obj.scene, item->label_id, &local);
+		scene_dims_union(menu->obj.scene, item->key_id, &local);
+		scene_dims_union(menu->obj.scene, item->desc_id, &local);
+		scene_dims_union(menu->obj.scene, item->preview_id, &local);
+		scene_dims_join(&local, &dims[SCENEBB_all]);
+
+		/* Get the dimensions all individual fields */
+		scene_dims_union(menu->obj.scene, item->label_id,
+				 &dims[SCENEBB_label]);
+		scene_dims_union(menu->obj.scene, item->key_id,
+				 &dims[SCENEBB_key]);
+		scene_dims_union(menu->obj.scene, item->desc_id,
+				 &dims[SCENEBB_desc]);
 	}
-
-	return 0;
 }
 
 int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr,
 		       struct scene_obj_menu *menu)
 {
 	const bool open = menu->obj.flags & SCENEOF_OPEN;
+	struct scene_obj_dims dims[SCENEBB_count];
 	struct expo *exp = scn->expo;
 	const bool stack = exp->popup;
 	const struct expo_theme *theme = &exp->theme;
@@ -239,6 +231,12 @@ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr,
 	int x, y;
 	int ret;
 
+	menu->obj.dims.x = 0;
+	menu->obj.dims.y = 0;
+
+	memset(dims, '\0', sizeof(dims));
+	scene_menu_calc_dims(scn, menu, dims);
+
 	x = menu->obj.bbox.x0;
 	y = menu->obj.bbox.y0;
 	if (menu->title_id) {
@@ -327,12 +325,23 @@ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr,
 				return log_msg_ret("hid", ret);
 		}
 
+		menu->obj.dims.x = 160;
 		if (!stack || open)
 			y += height + theme->menuitem_gap_y;
 	}
 
+	list_for_each_entry(item, &menu->item_head, sibling) {
+		scene_obj_set_width(menu->obj.scene, item->label_id,
+				    dims[SCENEBB_label].x + theme->menu_inset);
+		scene_obj_set_width(menu->obj.scene, item->key_id,
+				    dims[SCENEBB_key].x + theme->menu_inset);
+		scene_obj_set_width(menu->obj.scene, item->desc_id,
+				    dims[SCENEBB_desc].x + theme->menu_inset);
+	}
+
 	if (sel_id)
 		menu_point_to_item(menu, sel_id);
+	menu->obj.dims.y = dims[SCENEBB_all].y;
 	menu->obj.bbox.x1 = menu->obj.bbox.x0 + menu->obj.dims.x;
 	menu->obj.bbox.y1 = menu->obj.bbox.y0 + menu->obj.dims.y;
 	menu->obj.flags |= SCENEOF_SIZE_VALID;
-- 
2.43.0



More information about the U-Boot mailing list