From b9cd88381154d7115dbc69efeaa4c5ebf0936ec5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 29 Dec 2017 17:55:37 -0800 Subject: [PATCH] UI: Only default focus visible things. Also, default focus perm button. --- UI/MainScreen.cpp | 10 ++++++++-- ext/native/ui/ui_screen.cpp | 5 +++-- ext/native/ui/viewgroup.cpp | 4 +++- ext/native/ui/viewgroup.h | 8 ++++---- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 3ec5953109..f3276a41e8 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -762,6 +762,7 @@ void MainScreen::CreateViews() { tabRecentGames->OnHighlight.Handle(this, &MainScreen::OnGameHighlight); } + Button *grantStorageButton = nullptr; if (hasStorageAccess) { ScrollView *scrollAllGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollAllGames->SetTag("MainScreenAllGames"); @@ -819,7 +820,8 @@ void MainScreen::CreateViews() { LinearLayout *buttonHolder = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT)); buttonHolder->Add(new Spacer(new LinearLayoutParams(1.0f))); - buttonHolder->Add(new Button(mm->T("Give PPSSPP permission to access storage"), new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT)))->OnClick.Handle(this, &MainScreen::OnAllowStorage); + grantStorageButton = new Button(mm->T("Give PPSSPP permission to access storage"), new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT)); + buttonHolder->Add(grantStorageButton)->OnClick.Handle(this, &MainScreen::OnAllowStorage); buttonHolder->Add(new Spacer(new LinearLayoutParams(1.0f))); leftColumn->Add(new Spacer(new LinearLayoutParams(0.1f))); @@ -878,7 +880,11 @@ void MainScreen::CreateViews() { root_->Add(rightColumn); } - root_->SetDefaultFocusView(tabHolder_); + if (grantStorageButton) { + root_->SetDefaultFocusView(grantStorageButton); + } else if (tabHolder_->GetVisibility() != V_GONE) { + root_->SetDefaultFocusView(tabHolder_); + } I18NCategory *u = GetI18NCategory("Upgrade"); diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index 7581e5fcdc..6d8c81e4e1 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -33,8 +33,9 @@ void UIScreen::DoRecreateViews() { delete root_; root_ = nullptr; CreateViews(); - if (root_ && root_->GetDefaultFocusView()) { - root_->GetDefaultFocusView()->SetFocus(); + UI::View *defaultView = root_ ? root_->GetDefaultFocusView() : nullptr; + if (defaultView && defaultView->GetVisibility() == UI::V_VISIBLE) { + defaultView->SetFocus(); } recreateViews_ = false; diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index 5a9b4b425b..b6e9c08dcc 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -1555,7 +1555,9 @@ void UpdateViewHierarchy(ViewGroup *root) { std::lock_guard lock(focusLock); EnableFocusMovement(true); if (!GetFocusedView()) { - if (root->GetDefaultFocusView()) { + View *defaultView = root->GetDefaultFocusView(); + // Can't focus what you can't see. + if (defaultView && defaultView->GetVisibility() == V_VISIBLE) { root->GetDefaultFocusView()->SetFocus(); } else { root->SetFocus(); diff --git a/ext/native/ui/viewgroup.h b/ext/native/ui/viewgroup.h index b7de8c539c..6ede1fb9d2 100644 --- a/ext/native/ui/viewgroup.h +++ b/ext/native/ui/viewgroup.h @@ -24,7 +24,7 @@ struct NeighborResult { class ViewGroup : public View { public: - ViewGroup(LayoutParams *layoutParams = 0) : View(layoutParams), defaultFocusView_(0), hasDropShadow_(false), clip_(false) {} + ViewGroup(LayoutParams *layoutParams = 0) : View(layoutParams) {} virtual ~ViewGroup(); // Pass through external events to children. @@ -83,11 +83,11 @@ public: protected: std::mutex modifyLock_; // Hold this when changing the subviews. std::vector views_; - View *defaultFocusView_; + View *defaultFocusView_ = nullptr; Drawable bg_; float dropShadowExpand_ = 0.0f; - bool hasDropShadow_; - bool clip_; + bool hasDropShadow_ = false; + bool clip_ = false; }; // A frame layout contains a single child view (normally).