expo: Add width and height to objects
authorSimon Glass <sjg@chromium.org>
Thu, 1 Jun 2023 16:22:49 +0000 (10:22 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 14 Jul 2023 16:54:51 +0000 (12:54 -0400)
At present objects only have a position so it is not possible to determine
the amount of space they take up on the display.

Add width and height properties, using a struct to keep all the dimensions
together.

For now this is not used. Future work will set up these new properties.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/scene.c
boot/scene_menu.c
include/expo.h
test/boot/expo.c

index 2ac9bfc..8033d77 100644 (file)
@@ -201,8 +201,8 @@ int scene_obj_set_pos(struct scene *scn, uint id, int x, int y)
        obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
        if (!obj)
                return log_msg_ret("find", -ENOENT);
-       obj->x = x;
-       obj->y = y;
+       obj->dim.x = x;
+       obj->dim.y = y;
 
        return 0;
 }
@@ -272,8 +272,8 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode)
        struct udevice *cons = text_mode ? NULL : exp->cons;
        int x, y, ret;
 
-       x = obj->x;
-       y = obj->y;
+       x = obj->dim.x;
+       y = obj->dim.y;
 
        switch (obj->type) {
        case SCENEOBJT_NONE:
index 8b04d44..eed7565 100644 (file)
@@ -49,9 +49,9 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
        int y, cur_y;
        int ret;
 
-       y = menu->obj.y;
+       y = menu->obj.dim.y;
        if (menu->title_id) {
-               ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.x, y);
+               ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.dim.x, y);
                if (ret < 0)
                        return log_msg_ret("tit", ret);
 
@@ -89,18 +89,18 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
                 * pointer, then the key and the description
                 */
                if (item->label_id) {
-                       ret = scene_obj_set_pos(scn, item->label_id, menu->obj.x,
+                       ret = scene_obj_set_pos(scn, item->label_id, menu->obj.dim.x,
                                                y);
                        if (ret < 0)
                                return log_msg_ret("nam", ret);
                }
 
-               ret = scene_obj_set_pos(scn, item->key_id, menu->obj.x + 230,
+               ret = scene_obj_set_pos(scn, item->key_id, menu->obj.dim.x + 230,
                                        y);
                if (ret < 0)
                        return log_msg_ret("key", ret);
 
-               ret = scene_obj_set_pos(scn, item->desc_id, menu->obj.x + 280,
+               ret = scene_obj_set_pos(scn, item->desc_id, menu->obj.dim.x + 280,
                                        y);
                if (ret < 0)
                        return log_msg_ret("des", ret);
@@ -134,7 +134,7 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
                 * points to
                 */
                ret = scene_obj_set_pos(scn, menu->pointer_id,
-                                       menu->obj.x + 200, cur_y);
+                                       menu->obj.dim.x + 200, cur_y);
                if (ret < 0)
                        return log_msg_ret("ptr", ret);
        }
index b8f5327..5135954 100644 (file)
@@ -123,14 +123,28 @@ enum scene_obj_t {
 };
 
 /**
+ * struct scene_dim - Dimensions of an object
+ *
+ * @x: x position, in pixels from left side
+ * @y: y position, in pixels from top
+ * @w: width, in pixels
+ * @h: height, in pixels
+ */
+struct scene_dim {
+       int x;
+       int y;
+       int w;
+       int h;
+};
+
+/**
  * struct scene_obj - information about an object in a scene
  *
  * @scene: Scene that this object relates to
  * @name: Name of the object (allocated)
  * @id: ID number of the object
  * @type: Type of this object
- * @x: x position, in pixels from left side
- * @y: y position, in pixels from top
+ * @dim: Dimensions for this object
  * @hide: true if the object should be hidden
  * @sibling: Node to link this object to its siblings
  */
@@ -139,8 +153,7 @@ struct scene_obj {
        char *name;
        uint id;
        enum scene_obj_t type;
-       int x;
-       int y;
+       struct scene_dim dim;
        bool hide;
        struct list_head sibling;
 };
index 70750d3..10cb7b2 100644 (file)
@@ -250,8 +250,8 @@ static int expo_object_attr(struct unit_test_state *uts)
        ut_assert(id > 0);
 
        ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 123, 456));
-       ut_asserteq(123, img->obj.x);
-       ut_asserteq(456, img->obj.y);
+       ut_asserteq(123, img->obj.dim.x);
+       ut_asserteq(456, img->obj.dim.y);
 
        ut_asserteq(-ENOENT, scene_obj_set_pos(scn, OBJ_TEXT2, 0, 0));
 
@@ -307,8 +307,8 @@ static int expo_object_menu(struct unit_test_state *uts)
        ut_asserteq(0, menu->pointer_id);
 
        ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400));
-       ut_asserteq(50, menu->obj.x);
-       ut_asserteq(400, menu->obj.y);
+       ut_asserteq(50, menu->obj.dim.x);
+       ut_asserteq(400, menu->obj.dim.y);
 
        id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE,
                           "Main Menu", &tit);
@@ -354,24 +354,24 @@ static int expo_object_menu(struct unit_test_state *uts)
        ut_asserteq(id, menu->cur_item_id);
 
        /* the title should be at the top */
-       ut_asserteq(menu->obj.x, tit->obj.x);
-       ut_asserteq(menu->obj.y, tit->obj.y);
+       ut_asserteq(menu->obj.dim.x, tit->obj.dim.x);
+       ut_asserteq(menu->obj.dim.y, tit->obj.dim.y);
 
        /* the first item should be next */
-       ut_asserteq(menu->obj.x, name1->obj.x);
-       ut_asserteq(menu->obj.y + 32, name1->obj.y);
+       ut_asserteq(menu->obj.dim.x, name1->obj.dim.x);
+       ut_asserteq(menu->obj.dim.y + 32, name1->obj.dim.y);
 
-       ut_asserteq(menu->obj.x + 230, key1->obj.x);
-       ut_asserteq(menu->obj.y + 32, key1->obj.y);
+       ut_asserteq(menu->obj.dim.x + 230, key1->obj.dim.x);
+       ut_asserteq(menu->obj.dim.y + 32, key1->obj.dim.y);
 
-       ut_asserteq(menu->obj.x + 200, ptr->obj.x);
-       ut_asserteq(menu->obj.y + 32, ptr->obj.y);
+       ut_asserteq(menu->obj.dim.x + 200, ptr->obj.dim.x);
+       ut_asserteq(menu->obj.dim.y + 32, ptr->obj.dim.y);
 
-       ut_asserteq(menu->obj.x + 280, desc1->obj.x);
-       ut_asserteq(menu->obj.y + 32, desc1->obj.y);
+       ut_asserteq(menu->obj.dim.x + 280, desc1->obj.dim.x);
+       ut_asserteq(menu->obj.dim.y + 32, desc1->obj.dim.y);
 
-       ut_asserteq(-4, prev1->obj.x);
-       ut_asserteq(menu->obj.y + 32, prev1->obj.y);
+       ut_asserteq(-4, prev1->obj.dim.x);
+       ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
        ut_asserteq(false, prev1->obj.hide);
 
        expo_destroy(exp);