Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A55C1C7EE23 for ; Thu, 1 Jun 2023 16:30:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 99C1C865C1; Thu, 1 Jun 2023 18:25:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="k92xFod2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 684C2863A3; Thu, 1 Jun 2023 18:25:20 +0200 (CEST) Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 90D358639C for ; Thu, 1 Jun 2023 18:25:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-33b3fa03738so4157765ab.1 for ; Thu, 01 Jun 2023 09:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1685636692; x=1688228692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r5LA6coaNhlImgImG7OxhCfSJeLhNiKlxD4dJ9g0GSs=; b=k92xFod2mKS89tr+8ZjavVlTFtHINeUbtXwbHWUkrmMgqldWYqULUICkoLH1+zo9vl PlDM+MiFVKLUrxuQD2iwENPfsLjeQx7Q/cQFKz0xjlweUBP/mFoEIgrkmGm5FvEE2Nw3 IJCDBPLKlDjUXWMUL0QndkJ5dRCu+SXFDlr1s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685636692; x=1688228692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r5LA6coaNhlImgImG7OxhCfSJeLhNiKlxD4dJ9g0GSs=; b=EM2GAse7gOSFOfC3zklEX1puJk5ctXtio7zLO51Ur9NvvNwKOGw/2Olu1kDr2r0Bte LxGxsXMcZ13BZHJgxXlDm3iQgWHBwCG1YbKQM1j9HfeYPAfDSs303CHu1tS1Rpz0z59M G9WmbiNqKfDI/batWQg028RInKkHDuPNBoRYK9az1qNH3rgWX8+J1WU5+yK8/Ig/HU+L GcHXFl6/3v2VBWUo3j+RQRhN+hosIR97vUJ4wcjCkvsmBAbf23uZTIYhVYOTqk5AkRFe 9Rg/rfMOOY1tUPu9TF1V8Ssw3aI7zYWe4asls+yZLmUuG/8Pm9jMDnKIZPsimEiAz2ON 4tDg== X-Gm-Message-State: AC+VfDypvhPbs0fxeNy9dkhsEvjAEQ9TmbaVqD839uE2BAQt791zMGWo la1sOfdHAb3niIF4cZEd5IUTMf2bXxbXUmnidk4= X-Google-Smtp-Source: ACHHUZ779MlLgTGYJgTuX702MZ8P6+Hhnk1xDolIUtAzrckMAdcsU383Q8MeDofazN+N6kAHcWpKdg== X-Received: by 2002:a92:cb05:0:b0:337:a0d8:cdf9 with SMTP id s5-20020a92cb05000000b00337a0d8cdf9mr6334072ilo.28.1685636691925; Thu, 01 Jun 2023 09:24:51 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id l1-20020a922901000000b0033a6e7ee4e3sm3862098ilg.1.2023.06.01.09.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 09:24:51 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Simon Glass Subject: [PATCH 29/40] expo: Support simple themes Date: Thu, 1 Jun 2023 10:22:53 -0600 Message-ID: <20230601162404.220488-28-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog In-Reply-To: <20230601162404.220488-1-sjg@chromium.org> References: <20230601162404.220488-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 --- boot/expo.c | 20 ++++++++++++++++++++ boot/scene.c | 28 ++++++++++++++++++++++++++++ boot/scene_internal.h | 9 +++++++++ doc/develop/expo.rst | 9 +++++++-- include/expo.h | 24 ++++++++++++++++++++++++ test/boot/expo.c | 8 +++++++- 6 files changed, 95 insertions(+), 3 deletions(-) diff --git a/boot/expo.c b/boot/expo.c index 67cae3c7e28d..d5e935966bfd 100644 --- a/boot/expo.c +++ b/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; +} diff --git a/boot/scene.c b/boot/scene.c index 6d5e3c1f03dd..4dbe12a2b740 100644 --- a/boot/scene.c +++ b/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; +} diff --git a/boot/scene_internal.h b/boot/scene_internal.h index 00085a2f55d3..3387a90761ab 100644 --- a/boot/scene_internal.h +++ b/boot/scene_internal.h @@ -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 * diff --git a/doc/develop/expo.rst b/doc/develop/expo.rst index 54861b93acf8..2f4882899b6d 100644 --- a/doc/develop/expo.rst +++ b/doc/develop/expo.rst @@ -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 ----------------- diff --git a/include/expo.h b/include/expo.h index 6c45c403cf79..ea8f38913d8e 100644 --- a/include/expo.h +++ b/include/expo.h @@ -7,6 +7,7 @@ #ifndef __SCENE_H #define __SCENE_H +#include #include 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 */ diff --git a/test/boot/expo.c b/test/boot/expo.c index 493d050baf87..c0ef03b59112 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -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)); -- 2.41.0.rc0.172.g3f132b7071-goog