[Concept,12/16] expo: Factor out common calc_bbox code into scene_txtin.c

Message ID 20260118204303.1982533-13-sjg@u-boot.org
State New
Headers
Series expo: Continue preparations for textedit (part D) |

Commit Message

Simon Glass Jan. 18, 2026, 8:42 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Create a new file scene_txtin.c containing common code for text-input
scene objects (textline, textedit). Move the calc_bbox logic into
scene_txtin_calc_bbox() which is called directly from
scene_obj_calc_bbox()

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 boot/Makefile         |  2 +-
 boot/scene.c          | 13 ++++++++++---
 boot/scene_internal.h | 15 ++++++++-------
 boot/scene_textedit.c | 24 ++++++++++++++++++++++++
 boot/scene_textline.c | 16 ----------------
 boot/scene_txtin.c    | 30 ++++++++++++++++++++++++++++++
 6 files changed, 73 insertions(+), 27 deletions(-)
 create mode 100644 boot/scene_txtin.c
  

Patch

diff --git a/boot/Makefile b/boot/Makefile
index 39069014310..b9129a174c7 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -61,7 +61,7 @@  obj-$(CONFIG_$(PHASE_)LOAD_FIT) += common_fit.o
 
 obj-$(CONFIG_$(PHASE_)EXPO) += expo.o scene.o expo_build.o
 obj-$(CONFIG_$(PHASE_)EXPO_DUMP) += expo_dump.o
-obj-$(CONFIG_$(PHASE_)EXPO) += scene_menu.o scene_textline.o scene_textedit.o
+obj-$(CONFIG_$(PHASE_)EXPO) += scene_menu.o scene_textline.o scene_textedit.o scene_txtin.o
 obj-$(CONFIG_$(PHASE_)EXPO_TEST) += expo_test.o
 ifdef CONFIG_COREBOOT_SYSINFO
 obj-$(CONFIG_$(PHASE_)EXPO) += expo_build_cb.o
diff --git a/boot/scene.c b/boot/scene.c
index 9c02c9b36be..220fbf26b44 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -1440,7 +1440,6 @@  int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox bbox[])
 	case SCENEOBJT_IMAGE:
 	case SCENEOBJT_TEXT:
 	case SCENEOBJT_BOX:
-	case SCENEOBJT_TEXTEDIT:
 		return -ENOSYS;
 	case SCENEOBJT_MENU: {
 		struct scene_obj_menu *menu = (struct scene_obj_menu *)obj;
@@ -1452,8 +1451,16 @@  int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox bbox[])
 		struct scene_obj_textline *tline;
 
 		tline = (struct scene_obj_textline *)obj;
-		scene_textline_calc_bbox(tline, &bbox[SCENEBB_all],
-					 &bbox[SCENEBB_label]);
+		scene_txtin_calc_bbox(obj, &tline->tin, &bbox[SCENEBB_all],
+				      &bbox[SCENEBB_label]);
+		break;
+	}
+	case SCENEOBJT_TEXTEDIT: {
+		struct scene_obj_txtedit *ted;
+
+		ted = (struct scene_obj_txtedit *)obj;
+		scene_txtin_calc_bbox(obj, &ted->tin, &bbox[SCENEBB_all],
+				      &bbox[SCENEBB_label]);
 		break;
 	}
 	}
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index 1e5bd3d2a28..a3eb720c385 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -20,6 +20,7 @@  struct scene_obj_dims;
 struct scene_obj_menu;
 struct scene_obj_textline;
 struct scene_obj_txtedit;
+struct scene_txtin;
 struct scene_txt_generic;
 struct udevice;
 struct vidconsole_bbox;
@@ -497,16 +498,16 @@  void scene_menu_calc_bbox(struct scene_obj_menu *menu,
 			  struct vidconsole_bbox *bbox);
 
 /**
- * scene_textline_calc_bbox() - Calculate bounding box for the textline
+ * scene_txtin_calc_bbox() - Calculate bounding box for a text-input object
  *
- * @textline: Menu to process
- * @bbox: Returns bounding box of textline including prompt
+ * @obj: Object to process
+ * @tin: Text-input object info
+ * @bbox: Returns bounding box of object including label
  * @edit_bbox: Returns bounding box of editable part
- * Return: 0 if OK, -ve on error
  */
-void scene_textline_calc_bbox(struct scene_obj_textline *menu,
-			      struct vidconsole_bbox *bbox,
-			      struct vidconsole_bbox *label_bbox);
+void scene_txtin_calc_bbox(struct scene_obj *obj, struct scene_txtin *tin,
+			   struct vidconsole_bbox *bbox,
+			   struct vidconsole_bbox *edit_bbox);
 
 /**
  * scene_obj_calc_bbox() - Calculate bounding boxes for an object
diff --git a/boot/scene_textedit.c b/boot/scene_textedit.c
index de985c6f6e1..37138fc7542 100644
--- a/boot/scene_textedit.c
+++ b/boot/scene_textedit.c
@@ -56,6 +56,30 @@  int scene_txted_set_font(struct scene *scn, uint id, const char *font_name,
 	return scene_txt_set_font(scn, ted->tin.edit_id, font_name, font_size);
 }
 
+int scene_txted_calc_dims(struct scene_obj_txtedit *ted, struct udevice *cons)
+{
+	struct scene *scn = ted->obj.scene;
+	struct scene_obj_txt *txt;
+	int ret;
+
+	txt = scene_obj_find(scn, ted->tin.edit_id, SCENEOBJT_NONE);
+	if (!txt)
+		return log_msg_ret("txt", -ENOENT);
+
+	/*
+	 * Set the edit text's bbox to match the textedit's bbox. This ensures
+	 * SCENEOF_SIZE_VALID is set so vidconsole_measure() applies the width
+	 * limit for word-wrapping/clipping.
+	 */
+	ret = scene_obj_set_bbox(scn, ted->tin.edit_id,
+				 ted->obj.req_bbox.x0, ted->obj.req_bbox.y0,
+				 ted->obj.req_bbox.x1, ted->obj.req_bbox.y1);
+	if (ret < 0)
+		return log_msg_ret("sbb", ret);
+
+	return 0;
+}
+
 int scene_txted_arrange(struct scene *scn, struct expo_arrange_info *arr,
 			struct scene_obj_txtedit *ted)
 {
diff --git a/boot/scene_textline.c b/boot/scene_textline.c
index c0492896888..0f542dd590f 100644
--- a/boot/scene_textline.c
+++ b/boot/scene_textline.c
@@ -44,22 +44,6 @@  int scene_textline(struct scene *scn, const char *name, uint id,
 	return tline->obj.id;
 }
 
-void scene_textline_calc_bbox(struct scene_obj_textline *tline,
-			      struct vidconsole_bbox *bbox,
-			      struct vidconsole_bbox *edit_bbox)
-{
-	const struct expo_theme *theme = &tline->obj.scene->expo->theme;
-	int inset = theme->menu_inset;
-
-	bbox->valid = false;
-	scene_bbox_union(tline->obj.scene, tline->tin.label_id, inset, bbox);
-	scene_bbox_union(tline->obj.scene, tline->tin.edit_id, inset, bbox);
-
-	edit_bbox->valid = false;
-	scene_bbox_union(tline->obj.scene, tline->tin.edit_id, inset,
-			 edit_bbox);
-}
-
 int scene_textline_calc_dims(struct scene_obj_textline *tline,
 			     struct udevice *cons)
 {
diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c
new file mode 100644
index 00000000000..b2d8d0ad49e
--- /dev/null
+++ b/boot/scene_txtin.c
@@ -0,0 +1,30 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Common code for text-input scene objects (textline, textedit)
+ *
+ * Copyright 2026 Canonical Ltd
+ * Written by Simon Glass <simon.glass@canonical.com>
+ */
+
+#define LOG_CATEGORY	LOGC_EXPO
+
+#include <expo.h>
+#include <log.h>
+#include <video_console.h>
+#include "scene_internal.h"
+
+void scene_txtin_calc_bbox(struct scene_obj *obj, struct scene_txtin *tin,
+			   struct vidconsole_bbox *bbox,
+			   struct vidconsole_bbox *edit_bbox)
+{
+	struct scene *scn = obj->scene;
+	const struct expo_theme *theme = &scn->expo->theme;
+	int inset = theme->menu_inset;
+
+	bbox->valid = false;
+	scene_bbox_union(scn, tin->label_id, inset, bbox);
+	scene_bbox_union(scn, tin->edit_id, inset, bbox);
+
+	edit_bbox->valid = false;
+	scene_bbox_union(scn, tin->edit_id, inset, edit_bbox);
+}