[Concept,15/16] expo: Add scene_txtin_arrange() for common arrangement code

Message ID 20260118204303.1982533-16-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>

Factor out common arrangement code from scene_textline_arrange() and
scene_txted_arrange() into scene_txtin_arrange()

This handles label positioning and setting the SCENEOF_POINT flag.

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

 boot/scene_internal.h | 14 ++++++++++++++
 boot/scene_textedit.c | 26 ++++++--------------------
 boot/scene_textline.c | 39 +++++++++++++--------------------------
 boot/scene_txtin.c    | 26 ++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 46 deletions(-)
  

Patch

diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index b54bc1d426a..8c2196a7b11 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -521,6 +521,20 @@  void scene_menu_calc_bbox(struct scene_obj_menu *menu,
  */
 int scene_txtin_init(struct scene_txtin *tin, uint size, uint line_chars);
 
+/**
+ * scene_txtin_arrange() - Arrange common parts of a text-input object
+ *
+ * Sets the label position and SCENEOF_POINT flag
+ *
+ * @scn: Scene containing the object
+ * @arr: Arrangement info
+ * @obj: Object to arrange
+ * @tin: Text-input info
+ * Return: x position for edit object (positive), or -ve on error
+ */
+int scene_txtin_arrange(struct scene *scn, struct expo_arrange_info *arr,
+			struct scene_obj *obj, struct scene_txtin *tin);
+
 /**
  * scene_txtin_calc_bbox() - Calculate bounding box for a text-input object
  *
diff --git a/boot/scene_textedit.c b/boot/scene_textedit.c
index 9d0bfb2d552..160b9457a50 100644
--- a/boot/scene_textedit.c
+++ b/boot/scene_textedit.c
@@ -79,35 +79,21 @@  int scene_txted_calc_dims(struct scene_obj_txtedit *ted, struct udevice *cons)
 int scene_txted_arrange(struct scene *scn, struct expo_arrange_info *arr,
 			struct scene_obj_txtedit *ted)
 {
-	const bool open = ted->obj.flags & SCENEOF_OPEN;
-	const struct expo_theme *theme = &scn->expo->theme;
-	bool point;
-	int x, y;
+	int x;
 	int ret;
 
-	x = ted->obj.req_bbox.x0;
-	y = ted->obj.req_bbox.y0;
-	if (ted->tin.label_id) {
-		ret = scene_obj_set_pos(scn, ted->tin.label_id, x, y);
-		if (ret < 0)
-			return log_msg_ret("tit", ret);
-
-		x += arr->label_width + theme->textline_label_margin_x;
-	}
+	x = scene_txtin_arrange(scn, arr, &ted->obj, &ted->tin);
+	if (x < 0)
+		return log_msg_ret("arr", x);
 
 	/* constrain the edit text to fit within the textedit bbox */
-	ret = scene_obj_set_bbox(scn, ted->tin.edit_id, x, y,
+	ret = scene_obj_set_bbox(scn, ted->tin.edit_id, x, ted->obj.req_bbox.y0,
 				 ted->obj.req_bbox.x1, ted->obj.req_bbox.y1);
 	if (ret < 0)
 		return log_msg_ret("edi", ret);
 
-	point = scn->highlight_id == ted->obj.id;
-	point &= !open;
-	scene_obj_flag_clrset(scn, ted->tin.edit_id, SCENEOF_POINT,
-			      point ? SCENEOF_POINT : 0);
-
 	ted->obj.dims.x = x - ted->obj.req_bbox.x0;
-	ted->obj.dims.y = y - ted->obj.req_bbox.y0;
+	ted->obj.dims.y = 0;
 	scene_obj_set_size(scn, ted->obj.id, ted->obj.dims.x, ted->obj.dims.y);
 
 	return 0;
diff --git a/boot/scene_textline.c b/boot/scene_textline.c
index 960f5e8861f..f940be3ed28 100644
--- a/boot/scene_textline.c
+++ b/boot/scene_textline.c
@@ -71,37 +71,24 @@  int scene_textline_calc_dims(struct scene_obj_textline *tline,
 int scene_textline_arrange(struct scene *scn, struct expo_arrange_info *arr,
 			   struct scene_obj_textline *tline)
 {
-	const bool open = tline->obj.flags & SCENEOF_OPEN;
-	const struct expo_theme *theme = &scn->expo->theme;
-	bool point;
+	struct scene_obj *edit;
 	int x, y;
 	int ret;
 
-	x = tline->obj.req_bbox.x0;
+	x = scene_txtin_arrange(scn, arr, &tline->obj, &tline->tin);
+	if (x < 0)
+		return log_msg_ret("arr", x);
+
 	y = tline->obj.req_bbox.y0;
-	if (tline->tin.label_id) {
-		struct scene_obj *edit;
-
-		ret = scene_obj_set_pos(scn, tline->tin.label_id, x, y);
-		if (ret < 0)
-			return log_msg_ret("tit", ret);
-
-		x += arr->label_width + theme->textline_label_margin_x;
-		ret = scene_obj_set_pos(scn, tline->tin.edit_id, x, y);
-		if (ret < 0)
-			return log_msg_ret("til", ret);
-
-		edit = scene_obj_find(scn, tline->tin.edit_id, SCENEOBJT_NONE);
-		if (!edit)
-			return log_msg_ret("tie", -ENOENT);
-		x += edit->dims.x;
-		y += edit->dims.y;
-	}
+	ret = scene_obj_set_pos(scn, tline->tin.edit_id, x, y);
+	if (ret < 0)
+		return log_msg_ret("pos", ret);
 
-	point = scn->highlight_id == tline->obj.id;
-	point &= !open;
-	scene_obj_flag_clrset(scn, tline->tin.edit_id, SCENEOF_POINT,
-			      point ? SCENEOF_POINT : 0);
+	edit = scene_obj_find(scn, tline->tin.edit_id, SCENEOBJT_NONE);
+	if (!edit)
+		return log_msg_ret("fnd", -ENOENT);
+	x += edit->dims.x;
+	y += edit->dims.y;
 
 	tline->obj.dims.x = x - tline->obj.req_bbox.x0;
 	tline->obj.dims.y = y - tline->obj.req_bbox.y0;
diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c
index cd27f9b7115..dbd2555f71d 100644
--- a/boot/scene_txtin.c
+++ b/boot/scene_txtin.c
@@ -27,6 +27,32 @@  int scene_txtin_init(struct scene_txtin *tin, uint size, uint line_chars)
 	return 0;
 }
 
+int scene_txtin_arrange(struct scene *scn, struct expo_arrange_info *arr,
+			struct scene_obj *obj, struct scene_txtin *tin)
+{
+	const bool open = obj->flags & SCENEOF_OPEN;
+	const struct expo_theme *theme = &scn->expo->theme;
+	bool point;
+	int x;
+	int ret;
+
+	x = obj->req_bbox.x0;
+	if (tin->label_id) {
+		ret = scene_obj_set_pos(scn, tin->label_id, x, obj->req_bbox.y0);
+		if (ret < 0)
+			return log_msg_ret("lab", ret);
+
+		x += arr->label_width + theme->textline_label_margin_x;
+	}
+
+	point = scn->highlight_id == obj->id;
+	point &= !open;
+	scene_obj_flag_clrset(scn, tin->edit_id, SCENEOF_POINT,
+			      point ? SCENEOF_POINT : 0);
+
+	return x;
+}
+
 void scene_txtin_calc_bbox(struct scene_obj *obj, struct scene_txtin *tin,
 			   struct vidconsole_bbox *bbox,
 			   struct vidconsole_bbox *edit_bbox)