[Concept,13/16] expo: Add scene_obj_txtin() helper for text-input objects

Message ID 20260118204303.1982533-14-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 a static inline helper to get the scene_txtin pointer from a
scene object. This simplifies code that handles both textline and
textedit objects, since both have scene_txtin at the same offset.

Use this in scene_obj_calc_bbox() to combine the TEXTLINE and
TEXTEDIT cases.

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

 boot/scene.c          | 19 ++++---------------
 boot/scene_internal.h | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 15 deletions(-)
  

Patch

diff --git a/boot/scene.c b/boot/scene.c
index 220fbf26b44..5691cbce847 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -1447,23 +1447,12 @@  int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox bbox[])
 		scene_menu_calc_bbox(menu, bbox);
 		break;
 	}
-	case SCENEOBJT_TEXTLINE: {
-		struct scene_obj_textline *tline;
-
-		tline = (struct scene_obj_textline *)obj;
-		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]);
+	case SCENEOBJT_TEXTLINE:
+	case SCENEOBJT_TEXTEDIT:
+		scene_txtin_calc_bbox(obj, scene_obj_txtin(obj),
+				      &bbox[SCENEBB_all], &bbox[SCENEBB_label]);
 		break;
 	}
-	}
 
 	return 0;
 }
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index a3eb720c385..cc58a2264f6 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -29,6 +29,20 @@  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
  *