mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-17 10:24:49 +00:00
expo: Use flags for objects
We currently have just a 'hide' property for each object. In preparation for adding more properties, convert the struct to use a flags value, instead of individual booleans. This is more extensible. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
ae45d6cf5a
commit
ce72c9ec26
4 changed files with 40 additions and 7 deletions
17
boot/scene.c
17
boot/scene.c
|
@ -208,13 +208,26 @@ int scene_obj_set_pos(struct scene *scn, uint id, int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
int scene_obj_set_hide(struct scene *scn, uint id, bool hide)
|
int scene_obj_set_hide(struct scene *scn, uint id, bool hide)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = scene_obj_flag_clrset(scn, id, SCENEOF_HIDE,
|
||||||
|
hide ? SCENEOF_HIDE : 0);
|
||||||
|
if (ret)
|
||||||
|
return log_msg_ret("flg", ret);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set)
|
||||||
{
|
{
|
||||||
struct scene_obj *obj;
|
struct scene_obj *obj;
|
||||||
|
|
||||||
obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
|
obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return log_msg_ret("find", -ENOENT);
|
return log_msg_ret("find", -ENOENT);
|
||||||
obj->hide = hide;
|
obj->flags &= ~clr;
|
||||||
|
obj->flags |= set;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -358,7 +371,7 @@ int scene_render(struct scene *scn)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
list_for_each_entry(obj, &scn->obj_head, sibling) {
|
list_for_each_entry(obj, &scn->obj_head, sibling) {
|
||||||
if (!obj->hide) {
|
if (!(obj->flags & SCENEOF_HIDE)) {
|
||||||
ret = scene_obj_render(obj, exp->text_mode);
|
ret = scene_obj_render(obj, exp->text_mode);
|
||||||
if (ret && ret != -ENOTSUPP)
|
if (ret && ret != -ENOTSUPP)
|
||||||
return log_msg_ret("ren", ret);
|
return log_msg_ret("ren", ret);
|
||||||
|
|
|
@ -54,6 +54,17 @@ void *scene_obj_find(struct scene *scn, uint id, enum scene_obj_t type);
|
||||||
int scene_obj_add(struct scene *scn, const char *name, uint id,
|
int scene_obj_add(struct scene *scn, const char *name, uint id,
|
||||||
enum scene_obj_t type, uint size, struct scene_obj **objp);
|
enum scene_obj_t type, uint size, struct scene_obj **objp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scene_obj_flag_clrset() - Adjust object flags
|
||||||
|
*
|
||||||
|
* @scn: Scene to update
|
||||||
|
* @id: ID of object to update
|
||||||
|
* @clr: Bits to clear in the object's flags
|
||||||
|
* @set: Bits to set in the object's flags
|
||||||
|
* Returns 0 if OK, -ENOENT if the object was not found
|
||||||
|
*/
|
||||||
|
int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* scene_menu_arrange() - Set the position of things in the menu
|
* scene_menu_arrange() - Set the position of things in the menu
|
||||||
*
|
*
|
||||||
|
|
|
@ -137,6 +137,15 @@ struct scene_dim {
|
||||||
int h;
|
int h;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enum scene_obj_flags_t - flags for objects
|
||||||
|
*
|
||||||
|
* @SCENEOF_HIDE: object should be hidden
|
||||||
|
*/
|
||||||
|
enum scene_obj_flags_t {
|
||||||
|
SCENEOF_HIDE = 1 << 0,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct scene_obj - information about an object in a scene
|
* struct scene_obj - information about an object in a scene
|
||||||
*
|
*
|
||||||
|
@ -145,7 +154,7 @@ struct scene_dim {
|
||||||
* @id: ID number of the object
|
* @id: ID number of the object
|
||||||
* @type: Type of this object
|
* @type: Type of this object
|
||||||
* @dim: Dimensions for this object
|
* @dim: Dimensions for this object
|
||||||
* @hide: true if the object should be hidden
|
* @flags: Flags for this object
|
||||||
* @sibling: Node to link this object to its siblings
|
* @sibling: Node to link this object to its siblings
|
||||||
*/
|
*/
|
||||||
struct scene_obj {
|
struct scene_obj {
|
||||||
|
@ -154,7 +163,7 @@ struct scene_obj {
|
||||||
uint id;
|
uint id;
|
||||||
enum scene_obj_t type;
|
enum scene_obj_t type;
|
||||||
struct scene_dim dim;
|
struct scene_dim dim;
|
||||||
bool hide;
|
int flags;
|
||||||
struct list_head sibling;
|
struct list_head sibling;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -372,7 +372,7 @@ static int expo_object_menu(struct unit_test_state *uts)
|
||||||
|
|
||||||
ut_asserteq(-4, prev1->obj.dim.x);
|
ut_asserteq(-4, prev1->obj.dim.x);
|
||||||
ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
|
ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
|
||||||
ut_asserteq(false, prev1->obj.hide);
|
ut_asserteq(false, prev1->obj.flags & SCENEOF_HIDE);
|
||||||
|
|
||||||
expo_destroy(exp);
|
expo_destroy(exp);
|
||||||
|
|
||||||
|
@ -488,10 +488,10 @@ static int expo_render_image(struct unit_test_state *uts)
|
||||||
|
|
||||||
/* make sure only the preview for the second item is shown */
|
/* make sure only the preview for the second item is shown */
|
||||||
obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE);
|
obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE);
|
||||||
ut_asserteq(true, obj->hide);
|
ut_asserteq(true, obj->flags & SCENEOF_HIDE);
|
||||||
|
|
||||||
obj = scene_obj_find(scn, ITEM2_PREVIEW, SCENEOBJT_NONE);
|
obj = scene_obj_find(scn, ITEM2_PREVIEW, SCENEOBJT_NONE);
|
||||||
ut_asserteq(false, obj->hide);
|
ut_asserteq(false, obj->flags & SCENEOF_HIDE);
|
||||||
|
|
||||||
/* select it */
|
/* select it */
|
||||||
ut_assertok(expo_send_key(exp, BKEY_SELECT));
|
ut_assertok(expo_send_key(exp, BKEY_SELECT));
|
||||||
|
|
Loading…
Add table
Reference in a new issue