From f27850ec1d83045cd822f8d8a36d8801e7b5d4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 6 Jul 2023 16:34:54 +0200 Subject: [PATCH] Minor cleanup in MoveFocus, set tags on screen roots for debugging --- Common/UI/Root.cpp | 2 +- Common/UI/ViewGroup.cpp | 30 ++++++++++-------------------- UI/MainScreen.cpp | 2 ++ UI/OnScreenDisplay.cpp | 1 + 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index c2f7296588..9a1f08b201 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -133,7 +133,7 @@ void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets root->Layout(); } -void MoveFocus(ViewGroup *root, FocusDirection direction) { +static void MoveFocus(ViewGroup *root, FocusDirection direction) { View *focusedView = GetFocusedView(); if (!focusedView) { // Nothing was focused when we got in here. Focus the first non-group in the hierarchy. diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index 95de812ff1..f1360cf0bd 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -418,25 +418,6 @@ NeighborResult ViewGroup::FindNeighbor(View *view, FocusDirection direction, Nei } } - if (direction == FOCUS_PREV || direction == FOCUS_NEXT) { - switch (direction) { - case FOCUS_PREV: - // If view not found, no neighbor to find. - if (num == -1) - return NeighborResult(nullptr, 0.0f); - return NeighborResult(views_[(num + views_.size() - 1) % views_.size()], 0.0f); - - case FOCUS_NEXT: - // If view not found, no neighbor to find. - if (num == -1) - return NeighborResult(0, 0.0f); - return NeighborResult(views_[(num + 1) % views_.size()], 0.0f); - default: - // Can't happen - return NeighborResult(nullptr, 0.0f); - } - } - switch (direction) { case FOCUS_UP: case FOCUS_LEFT: @@ -472,10 +453,19 @@ NeighborResult ViewGroup::FindNeighbor(View *view, FocusDirection direction, Nei } return result; } - case FOCUS_PREV_PAGE: case FOCUS_NEXT_PAGE: return FindScrollNeighbor(view, Point(INFINITY, INFINITY), direction, result); + case FOCUS_PREV: + // If view not found, no neighbor to find. + if (num == -1) + return NeighborResult(nullptr, 0.0f); + return NeighborResult(views_[(num + views_.size() - 1) % views_.size()], 0.0f); + case FOCUS_NEXT: + // If view not found, no neighbor to find. + if (num == -1) + return NeighborResult(0, 0.0f); + return NeighborResult(views_[(num + 1) % views_.size()], 0.0f); default: ERROR_LOG(SYSTEM, "Bad focus direction %d", (int)direction); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index c285e677d2..254f8a31e7 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1260,6 +1260,8 @@ void MainScreen::CreateViews() { root_->SetDefaultFocusView(tabHolder_); } + root_->SetTag("mainroot"); + auto u = GetI18NCategory(I18NCat::UPGRADE); upgradeBar_ = 0; diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index a0f8178592..0a508faac0 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -286,5 +286,6 @@ std::string OnScreenMessagesView::DescribeText() const { void OSDOverlayScreen::CreateViews() { root_ = new UI::AnchorLayout(); + root_->SetTag("OSDOverlayScreen"); root_->Add(new OnScreenMessagesView(new UI::AnchorLayoutParams(0.0f, 0.0f, 0.0f, 0.0f))); }