diff options
| author | Simon Glass <[email protected]> | 2025-05-02 08:46:33 -0600 |
|---|---|---|
| committer | Simon Glass <[email protected]> | 2025-05-30 09:49:32 +0100 |
| commit | f04026a59f5384f32a452889fc199c06eaf1553e (patch) | |
| tree | ce4d093442b70f9ad64827d1c4880c5a5af4c714 /boot | |
| parent | 8636da86a2fb5f5f1a571f6cb3f12c0e8c207698 (diff) | |
expo: Separate dimensions from the bounding box
At present each object has a width and height and the bounding box is
implicit in that.
This is not flexible enough to handle objects which are larger than
their contents might need. For example, when centring a text object we
might want to have it stretch across the whole width of the display even
if the text itself does not need that much space.
Create a new 'dimensions' field and convert the existing width/height
into x1/y1 coordinates.
Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'boot')
| -rw-r--r-- | boot/scene.c | 31 | ||||
| -rw-r--r-- | boot/scene_menu.c | 7 | ||||
| -rw-r--r-- | boot/scene_textline.c | 18 |
3 files changed, 38 insertions, 18 deletions
diff --git a/boot/scene.c b/boot/scene.c index 49dac90ceed..325dd23641f 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -206,12 +206,17 @@ int scene_txt_set_font(struct scene *scn, uint id, const char *font_name, int scene_obj_set_pos(struct scene *scn, uint id, int x, int y) { struct scene_obj *obj; + int w, h; obj = scene_obj_find(scn, id, SCENEOBJT_NONE); if (!obj) return log_msg_ret("find", -ENOENT); + w = obj->bbox.x1 - obj->bbox.x0; + h = obj->bbox.y1 - obj->bbox.y0; obj->bbox.x0 = x; obj->bbox.y0 = y; + obj->bbox.x1 = obj->bbox.x0 + w; + obj->bbox.y1 = obj->bbox.y0 + h; return 0; } @@ -223,8 +228,9 @@ int scene_obj_set_size(struct scene *scn, uint id, int w, int h) obj = scene_obj_find(scn, id, SCENEOBJT_NONE); if (!obj) return log_msg_ret("find", -ENOENT); - obj->bbox.w = w; - obj->bbox.h = h; + obj->bbox.x1 = obj->bbox.x0 + w; + obj->bbox.y1 = obj->bbox.y0 + h; + obj->flags |= SCENEOF_SIZE_VALID; return 0; } @@ -419,8 +425,8 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode) if (obj->flags & SCENEOF_POINT) { vidconsole_push_colour(cons, fore, back, &old); video_fill_part(dev, x - theme->menu_inset, y, - x + obj->bbox.w, - y + obj->bbox.h, + obj->bbox.x1, + obj->bbox.y1, vid_priv->colour_bg); } vidconsole_set_cursor_pos(cons, x, y); @@ -765,8 +771,13 @@ int scene_calc_dims(struct scene *scn, bool do_menus) ret = scene_obj_get_hw(scn, obj->id, &width); if (ret < 0) return log_msg_ret("get", ret); - obj->bbox.w = width; - obj->bbox.h = ret; + obj->dims.x = width; + obj->dims.y = ret; + if (!(obj->flags & SCENEOF_SIZE_VALID)) { + obj->bbox.x1 = obj->bbox.x0 + width; + obj->bbox.y1 = obj->bbox.y0 + ret; + obj->flags |= SCENEOF_SIZE_VALID; + } } break; } @@ -917,13 +928,13 @@ int scene_bbox_union(struct scene *scn, uint id, int inset, if (bbox->valid) { bbox->x0 = min(bbox->x0, obj->bbox.x0 - inset); bbox->y0 = min(bbox->y0, obj->bbox.y0); - bbox->x1 = max(bbox->x1, obj->bbox.x0 + obj->bbox.w + inset); - bbox->y1 = max(bbox->y1, obj->bbox.y0 + obj->bbox.h); + bbox->x1 = max(bbox->x1, obj->bbox.x1 + inset); + bbox->y1 = max(bbox->y1, obj->bbox.y1); } else { bbox->x0 = obj->bbox.x0 - inset; bbox->y0 = obj->bbox.y0; - bbox->x1 = obj->bbox.x0 + obj->bbox.w + inset; - bbox->y1 = obj->bbox.y0 + obj->bbox.h; + bbox->x1 = obj->bbox.x1 + inset; + bbox->y1 = obj->bbox.y1; bbox->valid = true; } diff --git a/boot/scene_menu.c b/boot/scene_menu.c index c47c2030527..dbc6793e302 100644 --- a/boot/scene_menu.c +++ b/boot/scene_menu.c @@ -186,8 +186,8 @@ int scene_menu_calc_dims(struct scene_obj_menu *menu) } if (bbox.valid) { - menu->obj.bbox.w = bbox.x1 - bbox.x0; - menu->obj.bbox.h = bbox.y1 - bbox.y0; + menu->obj.dims.x = bbox.x1 - bbox.x0; + menu->obj.dims.y = bbox.y1 - bbox.y0; } return 0; @@ -295,6 +295,9 @@ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr, if (sel_id) menu_point_to_item(menu, sel_id); + menu->obj.bbox.x1 = menu->obj.bbox.x0 + menu->obj.dims.x; + menu->obj.bbox.y1 = menu->obj.bbox.y0 + menu->obj.dims.y; + menu->obj.flags |= SCENEOF_SIZE_VALID; return 0; } diff --git a/boot/scene_textline.c b/boot/scene_textline.c index a513d555ded..f1d6ff7607c 100644 --- a/boot/scene_textline.c +++ b/boot/scene_textline.c @@ -61,7 +61,8 @@ void scene_textline_calc_bbox(struct scene_obj_textline *tline, int scene_textline_calc_dims(struct scene_obj_textline *tline) { - struct scene *scn = tline->obj.scene; + struct scene_obj *obj = &tline->obj; + struct scene *scn = obj->scene; struct vidconsole_bbox bbox; struct scene_obj_txt *txt; int ret; @@ -76,11 +77,16 @@ int scene_textline_calc_dims(struct scene_obj_textline *tline) return log_msg_ret("nom", ret); if (bbox.valid) { - tline->obj.bbox.w = bbox.x1 - bbox.x0; - tline->obj.bbox.h = bbox.y1 - bbox.y0; - - scene_obj_set_size(scn, tline->edit_id, tline->obj.bbox.w, - tline->obj.bbox.h); + obj->dims.x = bbox.x1 - bbox.x0; + obj->dims.y = bbox.y1 - bbox.y0; + if (!(obj->flags & SCENEOF_SIZE_VALID)) { + obj->bbox.x1 = obj->bbox.x0 + obj->dims.x; + obj->bbox.y1 = obj->bbox.y0 + obj->dims.y; + obj->flags |= SCENEOF_SIZE_VALID; + } + scene_obj_set_size(scn, tline->edit_id, + obj->bbox.x1 - obj->bbox.x0, + obj->bbox.y1 - obj->bbox.y0); } return 0; |
