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 A98D9C77B7A for ; Thu, 1 Jun 2023 16:30:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EA6BA865D5; Thu, 1 Jun 2023 18:25:59 +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="HCEzD8/h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BB5FB8638A; Thu, 1 Jun 2023 18:25:21 +0200 (CEST) Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (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 3736C8639F for ; Thu, 1 Jun 2023 18:25:13 +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-x136.google.com with SMTP id e9e14a558f8ab-33c1e7743b7so4034895ab.1 for ; Thu, 01 Jun 2023 09:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1685636693; x=1688228693; 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=LZQWEH4oeFy0Wj1LyiYXahbjWg/CYnqisUmQJ4kBrXs=; b=HCEzD8/hx9G362L8TEM1Jwv8E3ucwre8pDOge4XPJbWnm6x96ms+I7r78qrSvz3wvu xlP3BSgLSdw/mqL4iTLAqi1jIzXNBhUj2HhfL6YZONaKGCIw/0MBpnuQD6e0KrCARC85 rq08z4DZbbVMOFpP3II277wYHzEcTKwo14VA8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685636693; x=1688228693; 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=LZQWEH4oeFy0Wj1LyiYXahbjWg/CYnqisUmQJ4kBrXs=; b=aQ2W8c+Kzqw3Dtxi2i1vzziFa6XqOh9aFosscE53hW94ElHrJEvBCvNY3IzXkzP/Jq ghYzMDCkqHk7nwDBASqstcNVeuKfTQqUNjxcj5d6T+pwiS/lWQCjvTlZhIgE6Vwb5J+Y nfHi89mTPpuzJx9EPS0+HEML18P1jKmLTGszCJAjC7KU9nuPMYMwJpRBWLOQg+aFJHZu vbfTDC6+tfb1eCP/wQ/+kfiVmSRs5X23f0Dg0s6o9hrRaG6kUkrVAwub8OYZZvzTnaOU MMyjRsyMdc0CmNeDPFqMfE4j4xJlTTWKIRTX/cWlm76bF686bgXEn14IbEWxXATggLQU nz7A== X-Gm-Message-State: AC+VfDwCAfkaIXxmTnmJlmzUjextHe4UsNCGrY4QnYp0r9K0rpWDTKrs sDO5nKV4JzDjEW3ixEuerd3JDHQjgScxo+ISXs8= X-Google-Smtp-Source: ACHHUZ424ARF0GyDGrPjvEiszfNagc1CMD1ZDDYzLHAhimN5pTVo3+0RaZ+8vp843gZzC1CHHaC8LQ== X-Received: by 2002:a05:6e02:5cf:b0:33b:b6b9:a79d with SMTP id l15-20020a056e0205cf00b0033bb6b9a79dmr5566392ils.31.1685636693001; Thu, 01 Jun 2023 09:24:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 09:24:52 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Simon Glass Subject: [PATCH 30/40] expo: Move menu-item selection into a function Date: Thu, 1 Jun 2023 10:22:54 -0600 Message-ID: <20230601162404.220488-29-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 The current implementation supports a 'pointer' object which points to the currently highlighted menu item. We want to support highlighting the label of the menu item instead, e.g. with inverse video. In this case we will need to 'unhighlight' the old item and highlight the new one. As a first step, move the pointer logic into a function. This fixes a bug where the item is hidden when it should not be. Signed-off-by: Simon Glass --- boot/scene_menu.c | 67 ++++++++++++++++++++++++++++++++++++++--------- test/boot/expo.c | 2 +- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/boot/scene_menu.c b/boot/scene_menu.c index fa79cecdbd93..154be7f0127f 100644 --- a/boot/scene_menu.c +++ b/boot/scene_menu.c @@ -33,6 +33,51 @@ 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 *item; + + list_for_each_entry(item, &menu->item_head, sibling) { + if (item->id == id) + return item; + } + + return NULL; +} + +/** + * update_pointers() - Update the pointer object and handle highlights + * + * @menu: Menu to update + * @id: ID of menu item to select/deselect + * @point: true if @id is being selected, false if it is being deselected + */ +static int update_pointers(struct scene_obj_menu *menu, uint id, bool point) +{ + struct scene *scn = menu->obj.scene; + const struct scene_menitem *item; + int ret; + + item = scene_menuitem_find(menu, id); + if (!item) + return log_msg_ret("itm", -ENOENT); + + /* adjust the pointer object to point to the selected item */ + if (menu->pointer_id && item && point) { + struct scene_obj *label; + + label = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE); + + ret = scene_obj_set_pos(scn, menu->pointer_id, + menu->obj.dim.x + 200, label->dim.y); + if (ret < 0) + return log_msg_ret("ptr", ret); + } + + return 0; +} + /** * menu_point_to_item() - Point to a particular menu item * @@ -40,7 +85,10 @@ void scene_menu_destroy(struct scene_obj_menu *menu) */ static void menu_point_to_item(struct scene_obj_menu *menu, uint item_id) { + if (menu->cur_item_id) + update_pointers(menu, menu->cur_item_id, false); menu->cur_item_id = item_id; + update_pointers(menu, item_id, true); } static int scene_bbox_union(struct scene *scn, uint id, @@ -125,6 +173,7 @@ int scene_menu_calc_dims(struct scene_obj_menu *menu) int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu) { struct scene_menitem *item; + uint sel_id; int y, cur_y; int ret; @@ -147,7 +196,7 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu) * small. This can be updated once text measuring is supported in * vidconsole */ - cur_y = -1; + sel_id = menu->cur_item_id; list_for_each_entry(item, &menu->item_head, sibling) { int height; @@ -160,8 +209,8 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu) y += height; /* select an item if not done already */ - if (!menu->cur_item_id) - menu_point_to_item(menu, item->id); + if (!sel_id) + sel_id = item->id; /* * Put the label on the left, then leave a space for the @@ -207,16 +256,8 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu) y += height; } - if (menu->pointer_id && cur_y != -1) { - /* - * put the pointer to the right of and level with the item it - * points to - */ - ret = scene_obj_set_pos(scn, menu->pointer_id, - menu->obj.dim.x + 200, cur_y); - if (ret < 0) - return log_msg_ret("ptr", ret); - } + if (sel_id) + menu_point_to_item(menu, sel_id); return 0; } diff --git a/test/boot/expo.c b/test/boot/expo.c index c0ef03b59112..453316ece7c3 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -378,7 +378,7 @@ static int expo_object_menu(struct unit_test_state *uts) ut_asserteq(-4, prev1->obj.dim.x); ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y); - ut_asserteq(false, prev1->obj.flags & SCENEOF_HIDE); + ut_asserteq(true, prev1->obj.flags & SCENEOF_HIDE); expo_destroy(exp); -- 2.41.0.rc0.172.g3f132b7071-goog