[Concept,16/16] expo: Enable textedit dimension calculation for word-wrap

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

Add textedit support to scene_calc_dims() by calling
scene_txted_calc_dims(), thus enabling proper dimension-calculation for
textedit objects. This is needed for word-wrapping.

Update expo_render_textedit() with the new expected value, now that
word-wrapping is working.

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

 boot/scene.c          | 24 ++++++++++++++++--------
 boot/scene_internal.h | 39 +++++++++++++++++++++++++--------------
 test/boot/expo.c      |  2 +-
 3 files changed, 42 insertions(+), 23 deletions(-)
  

Patch

diff --git a/boot/scene.c b/boot/scene.c
index 5691cbce847..3565bfd77de 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -773,7 +773,6 @@  int scene_calc_arrange(struct scene *scn, struct expo_arrange_info *arr)
 		case SCENEOBJT_IMAGE:
 		case SCENEOBJT_TEXT:
 		case SCENEOBJT_BOX:
-		case SCENEOBJT_TEXTEDIT:
 			break;
 		case SCENEOBJT_MENU: {
 			struct scene_obj_menu *menu;
@@ -782,14 +781,11 @@  int scene_calc_arrange(struct scene *scn, struct expo_arrange_info *arr)
 			label_id = menu->title_id;
 			break;
 		}
-		case SCENEOBJT_TEXTLINE: {
-			struct scene_obj_textline *tline;
-
-			tline = (struct scene_obj_textline *)obj,
-			label_id = tline->tin.label_id;
+		case SCENEOBJT_TEXTLINE:
+		case SCENEOBJT_TEXTEDIT:
+			label_id = scene_obj_txtin(obj)->label_id;
 			break;
 		}
-		}
 
 		if (label_id) {
 			int ret;
@@ -1517,7 +1513,6 @@  int scene_calc_dims(struct scene *scn)
 			case SCENEOBJT_NONE:
 			case SCENEOBJT_TEXT:
 			case SCENEOBJT_BOX:
-			case SCENEOBJT_TEXTEDIT:
 			case SCENEOBJT_IMAGE: {
 				int width;
 
@@ -1533,6 +1528,19 @@  int scene_calc_dims(struct scene *scn)
 			}
 			case SCENEOBJT_MENU:
 				break;
+			case SCENEOBJT_TEXTEDIT: {
+				struct scene_obj_txtedit *ted;
+
+				ted = (struct scene_obj_txtedit *)obj;
+				if (!scn->expo->cons || do_menus)
+					continue;
+
+				ret = scene_txted_calc_dims(ted, scn->expo->cons);
+				if (ret)
+					return log_msg_ret("ted", ret);
+
+				break;
+			}
 			case SCENEOBJT_TEXTLINE: {
 				struct scene_obj_textline *tline;
 
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index 8c2196a7b11..db11f9c0f60 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -29,20 +29,6 @@  enum scene_obj_t;
 
 typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv);
 
-/**
- * scene_obj_txtin() - Get text-input info from a scene object
- *
- * This works for both textline and textedit objects since they have
- * struct scene_txtin at the same offset (immediately after struct scene_obj).
- *
- * @obj: Object to get text-input info from
- * Return: pointer to the text-input info
- */
-static inline struct scene_txtin *scene_obj_txtin(struct scene_obj *obj)
-{
-	return (struct scene_txtin *)(obj + 1);
-}
-
 /**
  * enum scene_bbox_t - Parts of an object which can have a bounding box
  *
@@ -64,6 +50,20 @@  enum scene_bbox_t {
 	SCENEBB_count,
 };
 
+/**
+ * scene_obj_txtin() - Get text-input info from a scene object
+ *
+ * This works for both textline and textedit objects since they have
+ * struct scene_txtin at the same offset (immediately after struct scene_obj).
+ *
+ * @obj: Object to get text-input info from
+ * Return: pointer to the text-input info
+ */
+static inline struct scene_txtin *scene_obj_txtin(struct scene_obj *obj)
+{
+	return (struct scene_txtin *)(obj + 1);
+}
+
 /**
  * expo_lookup_scene_id() - Look up a scene ID
  *
@@ -501,6 +501,17 @@  int scene_dims_union(struct scene *scn, uint id, struct scene_obj_dims *dims);
 int scene_textline_calc_dims(struct scene_obj_textline *tline,
 			     struct udevice *cons);
 
+/**
+ * scene_txted_calc_dims() - Calculate the dimensions of a textedit
+ *
+ * Updates the width and height of the textedit based on its contents
+ *
+ * @ted: Textedit to update
+ * @cons: UCLASS_VIDEO_CONSOLE device (cannot be NULL)
+ * Returns 0 if OK, -ve on error
+ */
+int scene_txted_calc_dims(struct scene_obj_txtedit *ted, struct udevice *cons);
+
 /**
  * scene_menu_calc_bbox() - Calculate bounding boxes for the menu
  *
diff --git a/test/boot/expo.c b/test/boot/expo.c
index 95b029568d0..97b9bf82bb7 100644
--- a/test/boot/expo.c
+++ b/test/boot/expo.c
@@ -1533,7 +1533,7 @@  static int expo_render_textedit(struct unit_test_state *uts)
 	expo_set_scene_id(exp, SCENE1);
 	ut_assertok(scene_arrange(scn));
 	ut_assertok(expo_render(exp));
-	ut_asserteq(19493, video_compress_fb(uts, dev, false));
+	ut_asserteq(19860, video_compress_fb(uts, dev, false));
 
 	abuf_uninit(&buf);
 	abuf_uninit(&logo_copy);