]> Git Repo - J-u-boot.git/blobdiff - boot/scene_menu.c
Merge patch series "env: mmc: fix use of two separate partitions with proper type...
[J-u-boot.git] / boot / scene_menu.c
index 154be7f0127f834ad3f0a3536e44069dd6d2d4b3..80bd7457cb1a1c3888b078e1e47cd9126e9e97ad 100644 (file)
@@ -8,7 +8,6 @@
 
 #define LOG_CATEGORY   LOGC_EXPO
 
-#include <common.h>
 #include <dm.h>
 #include <expo.h>
 #include <malloc.h>
@@ -33,8 +32,8 @@ void scene_menu_destroy(struct scene_obj_menu *menu)
                scene_menuitem_destroy(item);
 }
 
-static struct scene_menitem *scene_menuitem_find(struct scene_obj_menu *menu,
-                                                int id)
+struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu,
+                                         int id)
 {
        struct scene_menitem *item;
 
@@ -46,6 +45,22 @@ static struct scene_menitem *scene_menuitem_find(struct scene_obj_menu *menu,
        return NULL;
 }
 
+struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu,
+                                             uint seq)
+{
+       struct scene_menitem *item;
+       uint i;
+
+       i = 0;
+       list_for_each_entry(item, &menu->item_head, sibling) {
+               if (i == seq)
+                       return item;
+               i++;
+       }
+
+       return NULL;
+}
+
 /**
  * update_pointers() - Update the pointer object and handle highlights
  *
@@ -56,6 +71,7 @@ static struct scene_menitem *scene_menuitem_find(struct scene_obj_menu *menu,
 static int update_pointers(struct scene_obj_menu *menu, uint id, bool point)
 {
        struct scene *scn = menu->obj.scene;
+       const bool stack = scn->expo->popup;
        const struct scene_menitem *item;
        int ret;
 
@@ -75,6 +91,12 @@ static int update_pointers(struct scene_obj_menu *menu, uint id, bool point)
                        return log_msg_ret("ptr", ret);
        }
 
+       if (stack) {
+               point &= scn->highlight_id == menu->obj.id;
+               scene_obj_flag_clrset(scn, item->label_id, SCENEOF_POINT,
+                                     point ? SCENEOF_POINT : 0);
+       }
+
        return 0;
 }
 
@@ -91,59 +113,35 @@ static void menu_point_to_item(struct scene_obj_menu *menu, uint item_id)
        update_pointers(menu, item_id, true);
 }
 
-static int scene_bbox_union(struct scene *scn, uint id,
-                           struct vidconsole_bbox *bbox)
-{
-       struct scene_obj *obj;
-
-       if (!id)
-               return 0;
-       obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
-       if (!obj)
-               return log_msg_ret("obj", -ENOENT);
-       if (bbox->valid) {
-               bbox->x0 = min(bbox->x0, obj->dim.x);
-               bbox->y0 = min(bbox->y0, obj->dim.y);
-               bbox->x1 = max(bbox->x1, obj->dim.x + obj->dim.w);
-               bbox->y1 = max(bbox->y1, obj->dim.y + obj->dim.h);
-       } else {
-               bbox->x0 = obj->dim.x;
-               bbox->y0 = obj->dim.y;
-               bbox->x1 = obj->dim.x + obj->dim.w;
-               bbox->y1 = obj->dim.y + obj->dim.h;
-               bbox->valid = true;
-       }
-
-       return 0;
-}
-
-/**
- * scene_menu_calc_bbox() - Calculate bounding boxes for the menu
- *
- * @menu: Menu to process
- * @bbox: Returns bounding box of menu including prompts
- * @label_bbox: Returns bounding box of labels
- */
-static void scene_menu_calc_bbox(struct scene_obj_menu *menu,
-                                struct vidconsole_bbox *bbox,
-                                struct vidconsole_bbox *label_bbox)
+void scene_menu_calc_bbox(struct scene_obj_menu *menu,
+                         struct vidconsole_bbox *bbox,
+                         struct vidconsole_bbox *label_bbox)
 {
+       const struct expo_theme *theme = &menu->obj.scene->expo->theme;
        const struct scene_menitem *item;
 
        bbox->valid = false;
-       scene_bbox_union(menu->obj.scene, menu->title_id, bbox);
+       scene_bbox_union(menu->obj.scene, menu->title_id, 0, bbox);
 
        label_bbox->valid = false;
 
        list_for_each_entry(item, &menu->item_head, sibling) {
-               scene_bbox_union(menu->obj.scene, item->label_id, bbox);
-               scene_bbox_union(menu->obj.scene, item->key_id, bbox);
-               scene_bbox_union(menu->obj.scene, item->desc_id, bbox);
-               scene_bbox_union(menu->obj.scene, item->preview_id, bbox);
+               scene_bbox_union(menu->obj.scene, item->label_id,
+                                theme->menu_inset, bbox);
+               scene_bbox_union(menu->obj.scene, item->key_id, 0, bbox);
+               scene_bbox_union(menu->obj.scene, item->desc_id, 0, bbox);
+               scene_bbox_union(menu->obj.scene, item->preview_id, 0, bbox);
 
                /* Get the bounding box of all labels */
-               scene_bbox_union(menu->obj.scene, item->label_id, label_bbox);
+               scene_bbox_union(menu->obj.scene, item->label_id,
+                                theme->menu_inset, label_bbox);
        }
+
+       /*
+        * subtract the final menuitem's gap to keep the insert the same top
+        * and bottom
+        */
+       label_bbox->y1 -= theme->menuitem_gap_y;
 }
 
 int scene_menu_calc_dims(struct scene_obj_menu *menu)
@@ -172,11 +170,16 @@ int scene_menu_calc_dims(struct scene_obj_menu *menu)
 
 int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 {
+       const bool open = menu->obj.flags & SCENEOF_OPEN;
+       struct expo *exp = scn->expo;
+       const bool stack = exp->popup;
+       const struct expo_theme *theme = &exp->theme;
        struct scene_menitem *item;
        uint sel_id;
-       int y, cur_y;
+       int x, y;
        int ret;
 
+       x = menu->obj.dim.x;
        y = menu->obj.dim.y;
        if (menu->title_id) {
                ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.dim.x, y);
@@ -187,7 +190,10 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
                if (ret < 0)
                        return log_msg_ret("hei", ret);
 
-               y += ret * 2;
+               if (stack)
+                       x += 200;
+               else
+                       y += ret * 2;
        }
 
        /*
@@ -198,9 +204,10 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
         */
        sel_id = menu->cur_item_id;
        list_for_each_entry(item, &menu->item_head, sibling) {
+               bool selected;
                int height;
 
-               ret = scene_obj_get_hw(scn, item->desc_id, NULL);
+               ret = scene_obj_get_hw(scn, item->label_id, NULL);
                if (ret < 0)
                        return log_msg_ret("get", ret);
                height = ret;
@@ -212,29 +219,30 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
                if (!sel_id)
                        sel_id = item->id;
 
+               selected = sel_id == item->id;
+
                /*
                 * Put the label on the left, then leave a space for the
                 * pointer, then the key and the description
                 */
-               if (item->label_id) {
-                       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.dim.x + 230,
-                                       y);
+               ret = scene_obj_set_pos(scn, item->label_id,
+                                       x + theme->menu_inset, y);
                if (ret < 0)
-                       return log_msg_ret("key", ret);
+                       return log_msg_ret("nam", ret);
+               scene_obj_set_hide(scn, item->label_id,
+                                  stack && !open && !selected);
 
-               ret = scene_obj_set_pos(scn, item->desc_id, menu->obj.dim.x + 280,
-                                       y);
-               if (ret < 0)
-                       return log_msg_ret("des", ret);
+               if (item->key_id) {
+                       ret = scene_obj_set_pos(scn, item->key_id, x + 230, y);
+                       if (ret < 0)
+                               return log_msg_ret("key", ret);
+               }
 
-               if (menu->cur_item_id == item->id)
-                       cur_y = y;
+               if (item->desc_id) {
+                       ret = scene_obj_set_pos(scn, item->desc_id, x + 280, y);
+                       if (ret < 0)
+                               return log_msg_ret("des", ret);
+               }
 
                if (item->preview_id) {
                        bool hide;
@@ -253,7 +261,8 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
                                return log_msg_ret("hid", ret);
                }
 
-               y += height;
+               if (!stack || open)
+                       y += height + theme->menuitem_gap_y;
        }
 
        if (sel_id)
@@ -307,6 +316,7 @@ static struct scene_menitem *scene_menu_find_key(struct scene *scn,
 int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
                        struct expo_action *event)
 {
+       const bool open = menu->obj.flags & SCENEOF_OPEN;
        struct scene_menitem *item, *cur, *key_item;
 
        cur = NULL;
@@ -331,7 +341,7 @@ int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
                                             struct scene_menitem, sibling)) {
                        item = list_entry(item->sibling.prev,
                                          struct scene_menitem, sibling);
-                       event->type = EXPOACT_POINT;
+                       event->type = EXPOACT_POINT_ITEM;
                        event->select.id = item->id;
                        log_debug("up to item %d\n", event->select.id);
                }
@@ -340,7 +350,7 @@ int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
                if (!list_is_last(&item->sibling, &menu->item_head)) {
                        item = list_entry(item->sibling.next,
                                          struct scene_menitem, sibling);
-                       event->type = EXPOACT_POINT;
+                       event->type = EXPOACT_POINT_ITEM;
                        event->select.id = item->id;
                        log_debug("down to item %d\n", event->select.id);
                }
@@ -351,8 +361,13 @@ int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
                log_debug("select item %d\n", event->select.id);
                break;
        case BKEY_QUIT:
-               event->type = EXPOACT_QUIT;
-               log_debug("quit\n");
+               if (scn->expo->popup && open) {
+                       event->type = EXPOACT_CLOSE;
+                       event->select.id = menu->obj.id;
+               } else {
+                       event->type = EXPOACT_QUIT;
+                       log_debug("menu quit\n");
+               }
                break;
        case '0'...'9':
                key_item = scene_menu_find_key(scn, menu, key);
@@ -380,10 +395,10 @@ int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
                return log_msg_ret("find", -ENOENT);
 
        /* Check that the text ID is valid */
-       if (!scene_obj_find(scn, desc_id, SCENEOBJT_TEXT))
+       if (!scene_obj_find(scn, label_id, SCENEOBJT_TEXT))
                return log_msg_ret("txt", -EINVAL);
 
-       item = calloc(1, sizeof(struct scene_obj_menu));
+       item = calloc(1, sizeof(struct scene_menitem));
        if (!item)
                return log_msg_ret("item", -ENOMEM);
        item->name = strdup(name);
@@ -499,3 +514,20 @@ int scene_menu_display(struct scene_obj_menu *menu)
 
        return -ENOTSUPP;
 }
+
+int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu)
+{
+       struct scene_menitem *item;
+
+       scene_render_deps(scn, menu->title_id);
+       scene_render_deps(scn, menu->cur_item_id);
+       scene_render_deps(scn, menu->pointer_id);
+
+       list_for_each_entry(item, &menu->item_head, sibling) {
+               scene_render_deps(scn, item->key_id);
+               scene_render_deps(scn, item->label_id);
+               scene_render_deps(scn, item->desc_id);
+       }
+
+       return 0;
+}
This page took 0.036287 seconds and 4 git commands to generate.