From 42a44e424366d59d7f98456e9e2f35314866372a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 28 Oct 2025 14:54:28 +0100 Subject: [PATCH] Improve inset handling --- Common/UI/Context.cpp | 9 ++++++--- Common/UI/Context.h | 4 +--- Common/UI/Root.cpp | 4 ++-- Common/UI/Root.h | 2 +- Common/UI/TabHolder.cpp | 2 +- Common/UI/UIScreen.cpp | 4 ++-- Common/UI/UIScreen.h | 1 + UI/EmuScreen.cpp | 2 +- UI/MainScreen.cpp | 9 ++++++--- UI/MiscScreens.cpp | 3 +++ UI/TabbedDialogScreen.h | 4 +++- 11 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Common/UI/Context.cpp b/Common/UI/Context.cpp index a0b1f1fb3e..61d23028ce 100644 --- a/Common/UI/Context.cpp +++ b/Common/UI/Context.cpp @@ -137,13 +137,16 @@ Bounds UIContext::GetScissorBounds() { return bounds_; } -Bounds UIContext::GetLayoutBounds() const { +Bounds UIContext::GetLayoutBounds(bool ignoreBottomInset) const { Bounds bounds = GetBounds(); float left = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT); float right = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT); float top = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP); - // float bottom = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM); + float bottom = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM); + if (ignoreBottomInset) { + bottom = 0.0f; + } // Note that we ignore bottom here, to let lists etc. extend to the bottom of the screen. // However, we will add the same space to the bottom of scrolled lists, so that you don't have to @@ -153,7 +156,7 @@ Bounds UIContext::GetLayoutBounds() const { bounds.x += left; bounds.w -= (left + right); bounds.y += top; - bounds.h -= top; + bounds.h -= (top + bottom); return bounds; } diff --git a/Common/UI/Context.h b/Common/UI/Context.h index f429b6480e..5826485884 100644 --- a/Common/UI/Context.h +++ b/Common/UI/Context.h @@ -113,7 +113,7 @@ public: // in dps, like dp_xres and dp_yres void SetBounds(const Bounds &b) { bounds_ = b; } const Bounds &GetBounds() const { return bounds_; } - Bounds GetLayoutBounds() const; + Bounds GetLayoutBounds(bool ignoreBottomInset = false) const; Draw::DrawContext *GetDrawContext() { return draw_; } const UI::Theme &GetTheme() const { return *theme; @@ -130,8 +130,6 @@ public: atlasInvalid_ = true; // will cause it to be reloaded on the next frame. } private: - void GenerateUIAtlas(); - Draw::DrawContext *draw_ = nullptr; Bounds bounds_; diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index 2007652855..503a84a4be 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -100,8 +100,8 @@ bool IsFocusMovementEnabled() { return focusMovementEnabled; } -void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets) { - Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds(); +void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset) { + Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds(ignoreBottomInset); MeasureSpec horiz(EXACTLY, rootBounds.w); MeasureSpec vert(EXACTLY, rootBounds.h); diff --git a/Common/UI/Root.h b/Common/UI/Root.h index 90c50811ae..bdb70bfa21 100644 --- a/Common/UI/Root.h +++ b/Common/UI/Root.h @@ -22,7 +22,7 @@ DialogResult DispatchEvents(); class ViewGroup; -void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets); +void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset); DialogResult UpdateViewHierarchy(ViewGroup *root); enum class KeyEventResult { diff --git a/Common/UI/TabHolder.cpp b/Common/UI/TabHolder.cpp index 3b611604f9..c9a41d4c69 100644 --- a/Common/UI/TabHolder.cpp +++ b/Common/UI/TabHolder.cpp @@ -58,7 +58,7 @@ TabHolder::TabHolder(Orientation orientation, float stripSize, TabHolderFlags fl void TabHolder::AddBack(UIScreen *parent) { if (tabContainer_) { auto di = GetI18NCategory(I18NCat::DIALOG); - tabContainer_->Add(new Choice(di->T("Back"), "", false, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 0.0f, Margins(0, 0, 10, 10))))->OnClick.Handle(parent, &UIScreen::OnBack); + tabContainer_->Add(new Choice(di->T("Back"), ImageID("I_NAVIGATE_BACK"), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 0.0f, Margins(0, 0, 10, 10))))->OnClick.Handle(parent, &UIScreen::OnBack); } } diff --git a/Common/UI/UIScreen.cpp b/Common/UI/UIScreen.cpp index 97a9896d05..385133d053 100644 --- a/Common/UI/UIScreen.cpp +++ b/Common/UI/UIScreen.cpp @@ -56,7 +56,7 @@ void UIScreen::DoRecreateViews() { // Update layout and refocus so things scroll into view. // This is for resizing down, when focused on something now offscreen. - UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_, ignoreInsets_); + UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_, ignoreInsets_, ignoreBottomInset_); UI::View *focused = UI::GetFocusedView(); if (focused) { root_->SubviewFocused(focused); @@ -229,7 +229,7 @@ ScreenRenderFlags UIScreen::render(ScreenRenderMode mode) { UIContext &uiContext = *screenManager()->getUIContext(); if (root_) { - UI::LayoutViewHierarchy(uiContext, root_, ignoreInsets_); + UI::LayoutViewHierarchy(uiContext, root_, ignoreInsets_, ignoreBottomInset_); } uiContext.PushTransform({translation_, scale_, alpha_}); diff --git a/Common/UI/UIScreen.h b/Common/UI/UIScreen.h index 394b04012f..2e45b15542 100644 --- a/Common/UI/UIScreen.h +++ b/Common/UI/UIScreen.h @@ -68,6 +68,7 @@ protected: Vec3 scale_ = Vec3(1.0f); float alpha_ = 1.0f; bool ignoreInsets_ = false; + bool ignoreBottomInset_ = false; bool ignoreInput_ = false; protected: diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index f7cfe9c84c..2880ef7c5d 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1941,7 +1941,7 @@ void EmuScreen::renderUI() { thin3d->SetViewport(viewport); if (root_) { - UI::LayoutViewHierarchy(*ctx, root_, false); + UI::LayoutViewHierarchy(*ctx, root_, false, false); root_->Draw(*ctx); } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 9cf3b3e6f1..803199ef4c 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -795,7 +795,7 @@ void GameBrowser::Refresh() { topBar->Add(new Choice(ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick); #else if ((browseFlags_ & BrowseFlags::BROWSE) && System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) { - // Collapse the button title on very small screens (Retroid Pocket). + // Collapse the button title on very small screens (Retroid Pocket) or portrait mode. std::string_view browseTitle = g_display.pixel_xres <= 640 ? "" : mm->T("Browse"); topBar->Add(new Choice(browseTitle, ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick); } @@ -1069,6 +1069,7 @@ void GameBrowser::OnHomebrewStore(UI::EventParams &e) { MainScreen::MainScreen() { g_BackgroundAudio.SetGame(Path()); + ignoreBottomInset_ = true; } MainScreen::~MainScreen() { @@ -1090,9 +1091,11 @@ void MainScreen::CreateRecentTab() { ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollRecentGames->SetTag("MainScreenRecentGames"); + GameBrowser *tabRecentGames = new GameBrowser(GetRequesterToken(), Path("!RECENT"), BrowseFlags::NONE, &g_Config.bGridView1, screenManager(), "", "", - new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scrollRecentGames->Add(tabRecentGames); gameBrowsers_.push_back(tabRecentGames); @@ -1111,7 +1114,7 @@ GameBrowser *MainScreen::CreateBrowserTab(const Path &path, std::string_view tit GameBrowser *gameBrowser = new GameBrowser(GetRequesterToken(), path, browseFlags, bGridView, screenManager(), mm->T(howToTitle), howToUri, - new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollView->Add(gameBrowser); gameBrowsers_.push_back(gameBrowser); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index f14dd77b5e..823358eff6 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -937,6 +937,9 @@ private: void CreditsScreen::CreateViews() { using namespace UI; + + ignoreBottomInset_ = false; + auto di = GetI18NCategory(I18NCat::DIALOG); auto cr = GetI18NCategory(I18NCat::PSPCREDITS); auto mm = GetI18NCategory(I18NCat::MAINMENU); diff --git a/UI/TabbedDialogScreen.h b/UI/TabbedDialogScreen.h index 3948ab02cc..d191e8123c 100644 --- a/UI/TabbedDialogScreen.h +++ b/UI/TabbedDialogScreen.h @@ -20,7 +20,9 @@ ENUM_CLASS_BITOPS(TabFlags); class TabbedUIDialogScreenWithGameBackground : public UIDialogScreenWithGameBackground { public: - TabbedUIDialogScreenWithGameBackground(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {} + TabbedUIDialogScreenWithGameBackground(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) { + ignoreBottomInset_ = true; + } void AddTab(const char *tag, std::string_view title, std::function createCallback, TabFlags flags = TabFlags::Default); void CreateViews() override;