expo: Place menu items to the right of all labels
At present a fixed position is used for menu items, 200 pixels to the
right of the left side of the labels. This means that a menu item with
a very long label may overlap the items.
It seems better to calculate the maximum label width and then place the
items to the right of all of them.
To implement this, add a new struct to containing arrangement
information. Calculate it before doing the actual arrangement. Add a
new style item which sets the amount of space from the right side of
the labels to left side of the items.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/boot/scene.c b/boot/scene.c
index 0135287..a483600 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -471,11 +471,59 @@
return 0;
}
-int scene_arrange(struct scene *scn)
+int scene_calc_arrange(struct scene *scn, struct expo_arrange_info *arr)
{
struct scene_obj *obj;
+
+ arr->label_width = 0;
+ list_for_each_entry(obj, &scn->obj_head, sibling) {
+ uint label_id = 0;
+ int width;
+
+ switch (obj->type) {
+ case SCENEOBJT_NONE:
+ case SCENEOBJT_IMAGE:
+ case SCENEOBJT_TEXT:
+ break;
+ case SCENEOBJT_MENU: {
+ struct scene_obj_menu *menu;
+
+ menu = (struct scene_obj_menu *)obj,
+ label_id = menu->title_id;
+ break;
+ }
+ case SCENEOBJT_TEXTLINE: {
+ struct scene_obj_textline *tline;
+
+ tline = (struct scene_obj_textline *)obj,
+ label_id = tline->label_id;
+ break;
+ }
+ }
+
+ if (label_id) {
+ int ret;
+
+ ret = scene_obj_get_hw(scn, label_id, &width);
+ if (ret < 0)
+ return log_msg_ret("hei", ret);
+ arr->label_width = max(arr->label_width, width);
+ }
+ }
+
+ return 0;
+}
+
+int scene_arrange(struct scene *scn)
+{
+ struct expo_arrange_info arr;
+ struct scene_obj *obj;
int ret;
+ ret = scene_calc_arrange(scn, &arr);
+ if (ret < 0)
+ return log_msg_ret("arr", ret);
+
list_for_each_entry(obj, &scn->obj_head, sibling) {
switch (obj->type) {
case SCENEOBJT_NONE:
@@ -486,7 +534,7 @@
struct scene_obj_menu *menu;
menu = (struct scene_obj_menu *)obj,
- ret = scene_menu_arrange(scn, menu);
+ ret = scene_menu_arrange(scn, &arr, menu);
if (ret)
return log_msg_ret("arr", ret);
break;
@@ -495,7 +543,7 @@
struct scene_obj_textline *tline;
tline = (struct scene_obj_textline *)obj,
- ret = scene_textline_arrange(scn, tline);
+ ret = scene_textline_arrange(scn, &arr, tline);
if (ret)
return log_msg_ret("arr", ret);
break;