Rather than hard-coding the distance between the labels and the key, measure the width of the pointer to determine the space needed.
Tweak a few tests according. It isn't possible to get the same result when the font-size differs. Signed-off-by: Simon Glass <s...@chromium.org> --- boot/scene_menu.c | 17 ++++++++++++++--- test/boot/expo.c | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/boot/scene_menu.c b/boot/scene_menu.c index 094489e2a40..b33e0a7d3b4 100644 --- a/boot/scene_menu.c +++ b/boot/scene_menu.c @@ -222,7 +222,7 @@ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr, struct scene_obj_menu *menu) { const bool open = menu->obj.flags & SCENEOF_OPEN; - struct scene_obj_dims dims[SCENEBB_count]; + struct scene_obj_dims dims[SCENEBB_count], pointer_dims; struct expo *exp = scn->expo; const bool stack = exp->popup; const struct expo_theme *theme = &exp->theme; @@ -231,6 +231,7 @@ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr, int startx, x, y; int ret; + memset(&pointer_dims, '\0', sizeof(pointer_dims)); menu->obj.dims.x = 0; menu->obj.dims.y = 0; @@ -256,6 +257,16 @@ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr, y += ret * 2; } + if (menu->pointer_id) { + const struct scene_obj *obj; + + obj = scene_obj_find(scn, menu->pointer_id, SCENEOBJT_NONE); + if (!obj) + return log_msg_ret("obj", -ENOENT); + + pointer_dims = obj->dims; + } + /* * Currently everything is hard-coded to particular columns so this * won't work on small displays and looks strange if the font size is @@ -295,9 +306,9 @@ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr, x += 200; /* space for the pointer */ - if (menu->pointer_id) { + if (pointer_dims.x) { menu->pointer_xofs = x - startx; - x += 30; + x += 12 + pointer_dims.x + 9; } if (item->key_id) { diff --git a/test/boot/expo.c b/test/boot/expo.c index 0289350df9c..b05e57b4f5a 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -424,10 +424,10 @@ static int expo_object_menu(struct unit_test_state *uts) ut_asserteq(menu->obj.bbox.x0 + 200, ptr->obj.bbox.x0); ut_asserteq(menu->obj.bbox.y0 + 32, ptr->obj.bbox.y0); - ut_asserteq(menu->obj.bbox.x0 + 230, key1->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.x0 + 229, key1->obj.bbox.x0); ut_asserteq(menu->obj.bbox.y0 + 32, key1->obj.bbox.y0); - ut_asserteq(menu->obj.bbox.x0 + 280, desc1->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.x0 + 279, desc1->obj.bbox.x0); ut_asserteq(menu->obj.bbox.y0 + 32, desc1->obj.bbox.y0); ut_asserteq(-4, prev1->obj.bbox.x0); -- 2.43.0