expo: Separate out reading the theme from applying it
Rename the existing expo_apply_theme() to expo_setup_theme() and adjust the former so that it applies a theme which has already been read into the struct. This will make it easier for tests to check theme adjustments, since they won't have to put them in a node. Add the white-on-black property into the theme struct while we are. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -261,7 +261,7 @@ int bootflow_menu_start(struct bootstd_priv *std, bool text_mode,
|
||||
return log_msg_ret("bma", ret);
|
||||
|
||||
if (ofnode_valid(std->theme)) {
|
||||
ret = expo_apply_theme(exp, std->theme);
|
||||
ret = expo_setup_theme(exp, std->theme);
|
||||
if (ret)
|
||||
return log_msg_ret("thm", ret);
|
||||
}
|
||||
|
||||
35
boot/expo.c
35
boot/expo.c
@@ -281,11 +281,28 @@ int expo_action_get(struct expo *exp, struct expo_action *act)
|
||||
return act->type == EXPOACT_NONE ? -EAGAIN : 0;
|
||||
}
|
||||
|
||||
int expo_apply_theme(struct expo *exp, ofnode node)
|
||||
int expo_apply_theme(struct expo *exp)
|
||||
{
|
||||
struct expo_theme *theme = &exp->theme;
|
||||
struct scene *scn;
|
||||
|
||||
if (exp->display)
|
||||
video_set_white_on_black(exp->display, theme->white_on_black);
|
||||
|
||||
list_for_each_entry(scn, &exp->scene_head, sibling) {
|
||||
int ret;
|
||||
|
||||
ret = scene_apply_theme(scn, theme);
|
||||
if (ret)
|
||||
return log_msg_ret("asn", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int expo_setup_theme(struct expo *exp, ofnode node)
|
||||
{
|
||||
struct scene *scn;
|
||||
struct expo_theme *theme = &exp->theme;
|
||||
bool white_on_black;
|
||||
int ret;
|
||||
|
||||
log_debug("Applying theme %s\n", ofnode_get_name(node));
|
||||
@@ -296,15 +313,11 @@ int expo_apply_theme(struct expo *exp, ofnode node)
|
||||
ofnode_read_u32(node, "menuitem-gap-y", &theme->menuitem_gap_y);
|
||||
ofnode_read_u32(node, "menu-title-margin-x",
|
||||
&theme->menu_title_margin_x);
|
||||
white_on_black = ofnode_read_bool(node, "white-on-black");
|
||||
if (exp->display)
|
||||
video_set_white_on_black(exp->display, white_on_black);
|
||||
theme->white_on_black = ofnode_read_bool(node, "white-on-black");
|
||||
|
||||
list_for_each_entry(scn, &exp->scene_head, sibling) {
|
||||
ret = scene_apply_theme(scn, theme);
|
||||
if (ret)
|
||||
return log_msg_ret("app", ret);
|
||||
}
|
||||
ret = expo_apply_theme(exp);
|
||||
if (ret)
|
||||
return log_msg_ret("asn", ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ static int do_cedit_run(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||
|
||||
node = ofnode_path("/bootstd/cedit-theme");
|
||||
if (ofnode_valid(node)) {
|
||||
ret = expo_apply_theme(cur_exp, node);
|
||||
ret = expo_setup_theme(cur_exp, node);
|
||||
if (ret)
|
||||
return CMD_RET_FAILURE;
|
||||
} else {
|
||||
|
||||
@@ -83,12 +83,15 @@ struct expo_action {
|
||||
* @menuitem_gap_y: Gap between menu items in pixels
|
||||
* @menu_title_margin_x: Gap between right side of menu title and left size of
|
||||
* menu label
|
||||
* @white_on_black: True to use white-on-black for the expo, false for
|
||||
* black-on-white
|
||||
*/
|
||||
struct expo_theme {
|
||||
u32 font_size;
|
||||
u32 menu_inset;
|
||||
u32 menuitem_gap_y;
|
||||
u32 menu_title_margin_x;
|
||||
bool white_on_black;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -994,12 +997,23 @@ int expo_send_key(struct expo *exp, int key);
|
||||
int expo_action_get(struct expo *exp, struct expo_action *act);
|
||||
|
||||
/**
|
||||
* expo_apply_theme() - Apply a theme to an expo
|
||||
* expo_setup_theme() - Read a theme from a node and apply it to an expo
|
||||
*
|
||||
* @exp: Expo to update
|
||||
* @node: Node containing the theme
|
||||
* Returns: 0 if OK, -ve on error
|
||||
*/
|
||||
int expo_apply_theme(struct expo *exp, ofnode node);
|
||||
int expo_setup_theme(struct expo *exp, ofnode node);
|
||||
|
||||
/**
|
||||
* expo_apply_theme() - Apply an expo's theme
|
||||
*
|
||||
* The theme to be applied must be set up exp->theme
|
||||
*
|
||||
* @exp: Expo to update
|
||||
* Returns: 0 if OK, -ve on error
|
||||
*/
|
||||
int expo_apply_theme(struct expo *exp);
|
||||
|
||||
/**
|
||||
* expo_build() - Build an expo from an FDT description
|
||||
|
||||
@@ -884,7 +884,7 @@ static int bootflow_menu_theme(struct unit_test_state *uts)
|
||||
ut_assertok(bootflow_menu_add_all(exp));
|
||||
node = ofnode_path("/bootstd/theme");
|
||||
ut_assert(ofnode_valid(node));
|
||||
ut_assertok(expo_apply_theme(exp, node));
|
||||
ut_assertok(expo_setup_theme(exp, node));
|
||||
|
||||
scn = expo_lookup_scene_id(exp, MAIN);
|
||||
ut_assertnonnull(scn);
|
||||
|
||||
@@ -302,7 +302,7 @@ static int expo_object_attr(struct unit_test_state *uts)
|
||||
|
||||
node = ofnode_path("/bootstd/theme");
|
||||
ut_assert(ofnode_valid(node));
|
||||
ut_assertok(expo_apply_theme(exp, node));
|
||||
ut_assertok(expo_setup_theme(exp, node));
|
||||
ut_asserteq(30, txt->gen.font_size);
|
||||
|
||||
expo_destroy(exp);
|
||||
|
||||
Reference in New Issue
Block a user