mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-15 17:34:43 +00:00
expo: Support simple themes
It is a pain to manually set the fonts of all objects to be consistent. Some spacing settings are also better set globally than by manually positioning each object. Add a 'theme' to the expo, to hold this information. For now it includes only the font size. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
699b0acb52
commit
2e59389704
6 changed files with 95 additions and 3 deletions
20
boot/expo.c
20
boot/expo.c
|
@ -231,3 +231,23 @@ 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)
|
||||
{
|
||||
struct scene *scn;
|
||||
struct expo_theme *theme = &exp->theme;
|
||||
int ret;
|
||||
|
||||
log_debug("Applying theme %s\n", ofnode_get_name(node));
|
||||
|
||||
memset(theme, '\0', sizeof(struct expo_theme));
|
||||
ofnode_read_u32(node, "font-size", &theme->font_size);
|
||||
|
||||
list_for_each_entry(scn, &exp->scene_head, sibling) {
|
||||
ret = scene_apply_theme(scn, theme);
|
||||
if (ret)
|
||||
return log_msg_ret("app", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
28
boot/scene.c
28
boot/scene.c
|
@ -466,3 +466,31 @@ int scene_calc_dims(struct scene *scn, bool do_menus)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scene_apply_theme(struct scene *scn, struct expo_theme *theme)
|
||||
{
|
||||
struct scene_obj *obj;
|
||||
int ret;
|
||||
|
||||
/* Avoid error-checking optional items */
|
||||
scene_txt_set_font(scn, scn->title_id, NULL, theme->font_size);
|
||||
|
||||
list_for_each_entry(obj, &scn->obj_head, sibling) {
|
||||
switch (obj->type) {
|
||||
case SCENEOBJT_NONE:
|
||||
case SCENEOBJT_IMAGE:
|
||||
case SCENEOBJT_MENU:
|
||||
break;
|
||||
case SCENEOBJT_TEXT:
|
||||
scene_txt_set_font(scn, obj->id, NULL,
|
||||
theme->font_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = scene_arrange(scn);
|
||||
if (ret)
|
||||
return log_msg_ret("arr", ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -89,6 +89,15 @@ int scene_calc_dims(struct scene *scn, bool do_menus);
|
|||
*/
|
||||
int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu);
|
||||
|
||||
/**
|
||||
* scene_apply_theme() - Apply a theme to a scene
|
||||
*
|
||||
* @scn: Scene to update
|
||||
* @theme: Theme to apply
|
||||
* Returns: 0 if OK, -ve on error
|
||||
*/
|
||||
int scene_apply_theme(struct scene *scn, struct expo_theme *theme);
|
||||
|
||||
/**
|
||||
* scene_menu_send_key() - Send a key to a menu for processing
|
||||
*
|
||||
|
|
|
@ -155,8 +155,13 @@ such as scanning devices for more bootflows.
|
|||
Themes
|
||||
------
|
||||
|
||||
Expo does not itself support themes. The bootflow_menu implement supposed a
|
||||
basic theme, applying font sizes to the various text objects in the expo.
|
||||
Expo supports simple themes, for setting the font size, for example. Use the
|
||||
expo_apply_theme() function to load a theme, passing a node with the required
|
||||
properties:
|
||||
|
||||
font-size
|
||||
Font size to use for all text (type: u32)
|
||||
|
||||
|
||||
API documentation
|
||||
-----------------
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef __SCENE_H
|
||||
#define __SCENE_H
|
||||
|
||||
#include <dm/ofnode_decl.h>
|
||||
#include <linux/list.h>
|
||||
|
||||
struct udevice;
|
||||
|
@ -42,6 +43,19 @@ struct expo_action {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* struct expo_theme - theme for the expo
|
||||
*
|
||||
* @font_size: Default font size for all text
|
||||
* @menu_inset: Inset width (on each side and top/bottom) for menu items
|
||||
* @menuitem_gap_y: Gap between menu items in pixels
|
||||
*/
|
||||
struct expo_theme {
|
||||
u32 font_size;
|
||||
u32 menu_inset;
|
||||
u32 menuitem_gap_y;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct expo - information about an expo
|
||||
*
|
||||
|
@ -57,6 +71,7 @@ struct expo_action {
|
|||
* type set to EXPOACT_NONE if there is no action
|
||||
* @text_mode: true to use text mode for the menu (no vidconsole)
|
||||
* @priv: Private data for the controller
|
||||
* @theme: Information about fonts styles, etc.
|
||||
* @scene_head: List of scenes
|
||||
* @str_head: list of strings
|
||||
*/
|
||||
|
@ -69,6 +84,7 @@ struct expo {
|
|||
struct expo_action action;
|
||||
bool text_mode;
|
||||
void *priv;
|
||||
struct expo_theme theme;
|
||||
struct list_head scene_head;
|
||||
struct list_head str_head;
|
||||
};
|
||||
|
@ -583,4 +599,12 @@ 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
|
||||
*
|
||||
* @exp: Expo to update
|
||||
* @node: Node containing the theme
|
||||
*/
|
||||
int expo_apply_theme(struct expo *exp, ofnode node);
|
||||
|
||||
#endif /*__SCENE_H */
|
||||
|
|
|
@ -226,7 +226,7 @@ static int expo_object(struct unit_test_state *uts)
|
|||
}
|
||||
BOOTSTD_TEST(expo_object, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
||||
|
||||
/* Check setting object attributes */
|
||||
/* Check setting object attributes and using themes */
|
||||
static int expo_object_attr(struct unit_test_state *uts)
|
||||
{
|
||||
struct scene_obj_menu *menu;
|
||||
|
@ -236,6 +236,7 @@ static int expo_object_attr(struct unit_test_state *uts)
|
|||
struct expo *exp;
|
||||
ulong start_mem;
|
||||
char name[100];
|
||||
ofnode node;
|
||||
char *data;
|
||||
int id;
|
||||
|
||||
|
@ -273,6 +274,11 @@ static int expo_object_attr(struct unit_test_state *uts)
|
|||
ut_asserteq(-ENOENT, scene_menu_set_title(scn, OBJ_TEXT2, OBJ_TEXT));
|
||||
ut_asserteq(-EINVAL, scene_menu_set_title(scn, OBJ_MENU, OBJ_TEXT2));
|
||||
|
||||
node = ofnode_path("/bootstd/theme");
|
||||
ut_assert(ofnode_valid(node));
|
||||
ut_assertok(expo_apply_theme(exp, node));
|
||||
ut_asserteq(30, txt->font_size);
|
||||
|
||||
expo_destroy(exp);
|
||||
|
||||
ut_assertok(ut_check_delta(start_mem));
|
||||
|
|
Loading…
Add table
Reference in a new issue