summaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorSimon Glass <[email protected]>2025-05-02 08:46:37 -0600
committerSimon Glass <[email protected]>2025-05-30 09:49:32 +0100
commit5a80996cb6a285d09c03d687dc9ad793f12e7bf1 (patch)
treef380eb465821947d9af64a8d9364a446c9065713 /boot
parent5ea2b533ed037b8f6f89c33f13dcf6188ba9162d (diff)
expo: Create a struct for generic text attributes
In preparation for adding more text types, refactor the common fields into a new structure. This will allow common code to be used. Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'boot')
-rw-r--r--boot/cedit.c2
-rw-r--r--boot/scene.c65
-rw-r--r--boot/scene_menu.c12
-rw-r--r--boot/scene_textline.c10
4 files changed, 55 insertions, 34 deletions
diff --git a/boot/cedit.c b/boot/cedit.c
index 792ab6d65bd..0f7a8657c58 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -271,7 +271,7 @@ static int get_cur_menuitem_text(const struct scene_obj_menu *menu,
if (!txt)
return log_msg_ret("txt", -ENOENT);
- str = expo_get_str(scn->expo, txt->str_id);
+ str = expo_get_str(scn->expo, txt->gen.str_id);
if (!str)
return log_msg_ret("str", -ENOENT);
*strp = str;
diff --git a/boot/scene.c b/boot/scene.c
index ea329252d28..99623d2d3a8 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -142,6 +142,31 @@ int scene_img(struct scene *scn, const char *name, uint id, char *data,
return img->obj.id;
}
+int scene_txt_generic_init(struct expo *exp, struct scene_txt_generic *gen,
+ const char *name, uint str_id, const char *str)
+{
+ int ret;
+
+ if (str) {
+ ret = expo_str(exp, name, str_id, str);
+ if (ret < 0)
+ return log_msg_ret("str", ret);
+ if (str_id && ret != str_id)
+ return log_msg_ret("id", -EEXIST);
+ str_id = ret;
+ } else {
+ ret = resolve_id(exp, str_id);
+ if (ret < 0)
+ return log_msg_ret("nst", ret);
+ if (str_id && ret != str_id)
+ return log_msg_ret("nid", -EEXIST);
+ }
+
+ gen->str_id = str_id;
+
+ return 0;
+}
+
int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
struct scene_obj_txt **txtp)
{
@@ -154,8 +179,9 @@ int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
if (ret < 0)
return log_msg_ret("obj", ret);
- txt->str_id = str_id;
-
+ ret = scene_txt_generic_init(scn->expo, &txt->gen, name, str_id, NULL);
+ if (ret)
+ return log_msg_ret("stg", ret);
if (txtp)
*txtp = txt;
@@ -168,21 +194,15 @@ int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
struct scene_obj_txt *txt;
int ret;
- ret = expo_str(scn->expo, name, str_id, str);
- if (ret < 0)
- return log_msg_ret("str", ret);
- if (str_id && ret != str_id)
- return log_msg_ret("id", -EEXIST);
- str_id = ret;
-
ret = scene_obj_add(scn, name, id, SCENEOBJT_TEXT,
sizeof(struct scene_obj_txt),
(struct scene_obj **)&txt);
if (ret < 0)
return log_msg_ret("obj", ret);
- txt->str_id = str_id;
-
+ ret = scene_txt_generic_init(scn->expo, &txt->gen, name, str_id, str);
+ if (ret)
+ return log_msg_ret("tsg", ret);
if (txtp)
*txtp = txt;
@@ -197,8 +217,8 @@ int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
txt = scene_obj_find(scn, id, SCENEOBJT_TEXT);
if (!txt)
return log_msg_ret("find", -ENOENT);
- txt->font_name = font_name;
- txt->font_size = font_size;
+ txt->gen.font_name = font_name;
+ txt->gen.font_size = font_size;
return 0;
}
@@ -313,13 +333,13 @@ int scene_obj_get_hw(struct scene *scn, uint id, int *widthp)
return height;
}
case SCENEOBJT_TEXT: {
- struct scene_obj_txt *txt = (struct scene_obj_txt *)obj;
+ struct scene_txt_generic *gen = &((struct scene_obj_txt *)obj)->gen;
struct expo *exp = scn->expo;
struct vidconsole_bbox bbox;
const char *str;
int len, ret;
- str = expo_get_str(exp, txt->str_id);
+ str = expo_get_str(exp, gen->str_id);
if (!str)
return log_msg_ret("str", -ENOENT);
len = strlen(str);
@@ -331,8 +351,8 @@ int scene_obj_get_hw(struct scene *scn, uint id, int *widthp)
return 16;
}
- ret = vidconsole_measure(scn->expo->cons, txt->font_name,
- txt->font_size, str, -1, &bbox, NULL);
+ ret = vidconsole_measure(scn->expo->cons, gen->font_name,
+ gen->font_size, str, -1, &bbox, NULL);
if (ret)
return log_msg_ret("mea", ret);
if (widthp)
@@ -424,22 +444,23 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode)
break;
}
case SCENEOBJT_TEXT: {
- struct scene_obj_txt *txt = (struct scene_obj_txt *)obj;
+ struct scene_txt_generic *gen =
+ &((struct scene_obj_txt *)obj)->gen;
const char *str;
if (!cons)
return -ENOTSUPP;
- if (txt->font_name || txt->font_size) {
+ if (gen->font_name || gen->font_size) {
ret = vidconsole_select_font(cons,
- txt->font_name,
- txt->font_size);
+ gen->font_name,
+ gen->font_size);
} else {
ret = vidconsole_select_font(cons, NULL, 0);
}
if (ret && ret != -ENOSYS)
return log_msg_ret("font", ret);
- str = expo_get_str(exp, txt->str_id);
+ str = expo_get_str(exp, gen->str_id);
if (str) {
struct video_priv *vid_priv;
struct vidconsole_colour old;
diff --git a/boot/scene_menu.c b/boot/scene_menu.c
index 96ac726ebcd..de433ece6ee 100644
--- a/boot/scene_menu.c
+++ b/boot/scene_menu.c
@@ -359,7 +359,7 @@ static struct scene_menitem *scene_menu_find_key(struct scene *scn,
txt = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT);
if (txt) {
- str = expo_get_str(scn->expo, txt->str_id);
+ str = expo_get_str(scn->expo, txt->gen.str_id);
if (str && *str == key)
return item;
}
@@ -562,7 +562,7 @@ int scene_menu_display(struct scene_obj_menu *menu)
if (!txt)
return log_msg_ret("txt", -EINVAL);
- str = expo_get_str(exp, txt->str_id);
+ str = expo_get_str(exp, txt->gen.str_id);
printf("%s\n\n", str);
}
@@ -570,7 +570,7 @@ int scene_menu_display(struct scene_obj_menu *menu)
return 0;
pointer = scene_obj_find(scn, menu->pointer_id, SCENEOBJT_TEXT);
- pstr = expo_get_str(scn->expo, pointer->str_id);
+ pstr = expo_get_str(scn->expo, pointer->gen.str_id);
list_for_each_entry(item, &menu->item_head, sibling) {
struct scene_obj_txt *key = NULL, *label = NULL;
@@ -579,15 +579,15 @@ int scene_menu_display(struct scene_obj_menu *menu)
key = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT);
if (key)
- kstr = expo_get_str(exp, key->str_id);
+ kstr = expo_get_str(exp, key->gen.str_id);
label = scene_obj_find(scn, item->label_id, SCENEOBJT_TEXT);
if (label)
- lstr = expo_get_str(exp, label->str_id);
+ lstr = expo_get_str(exp, label->gen.str_id);
desc = scene_obj_find(scn, item->desc_id, SCENEOBJT_TEXT);
if (desc)
- dstr = expo_get_str(exp, desc->str_id);
+ dstr = expo_get_str(exp, desc->gen.str_id);
printf("%3s %3s %-10s %s\n",
pointer && menu->cur_item_id == item->id ? pstr : "",
diff --git a/boot/scene_textline.c b/boot/scene_textline.c
index f1d6ff7607c..7bc35a997dc 100644
--- a/boot/scene_textline.c
+++ b/boot/scene_textline.c
@@ -71,8 +71,8 @@ int scene_textline_calc_dims(struct scene_obj_textline *tline)
if (!txt)
return log_msg_ret("dim", -ENOENT);
- ret = vidconsole_nominal(scn->expo->cons, txt->font_name,
- txt->font_size, tline->max_chars, &bbox);
+ ret = vidconsole_nominal(scn->expo->cons, txt->gen.font_name,
+ txt->gen.font_size, tline->max_chars, &bbox);
if (ret)
return log_msg_ret("nom", ret);
@@ -191,10 +191,10 @@ int scene_textline_render_deps(struct scene *scn,
if (!txt)
return log_msg_ret("cur", -ENOENT);
- if (txt->font_name || txt->font_size) {
+ if (txt->gen.font_name || txt->gen.font_size) {
ret = vidconsole_select_font(cons,
- txt->font_name,
- txt->font_size);
+ txt->gen.font_name,
+ txt->gen.font_size);
} else {
ret = vidconsole_select_font(cons, NULL, 0);
}