[Concept,13/16] expo: Add scene_obj_txtin() helper for text-input objects
Commit Message
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(-)
@@ -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;
}
@@ -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
*