From 160e2c4f9b0e93e4abb80410219db6a9742b8614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 14 Mar 2026 13:05:04 +0100 Subject: [PATCH] Refactor: Call GetLayoutBounds on the screen instead of the context where possible. This will allow screens to influence the layout bounds in a unified way --- Common/UI/Context.h | 2 +- Common/UI/PopupScreens.cpp | 9 +++++---- Common/UI/ScrollView.cpp | 2 +- Common/UI/UIScreen.cpp | 4 ++++ Common/UI/UIScreen.h | 2 ++ UI/ControlMappingScreen.cpp | 5 +++-- UI/CustomButtonMappingScreen.cpp | 2 +- UI/DebugOverlay.cpp | 12 ++++++------ UI/DevScreens.cpp | 2 +- UI/EmuScreen.cpp | 6 +++--- UI/GPUDriverTestScreen.cpp | 5 +++-- UI/MiscScreens.cpp | 2 +- UI/MiscScreens.h | 2 +- UI/OnScreenDisplay.cpp | 3 +-- UI/OnScreenDisplay.h | 1 - 15 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Common/UI/Context.h b/Common/UI/Context.h index 7d1e362001..bf2f8aa902 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(bool ignoreBottomInset = false) const; + Bounds GetLayoutBounds(bool ignoreBottomInset) const; Draw::DrawContext *GetDrawContext() const { return draw_; } const UI::Theme &GetTheme() const { return *theme; diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index 40fe12c3c0..8adffc00e6 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -137,9 +137,10 @@ void PopupScreen::CreateViews() { anchor->Overflow(false); root_ = anchor; - const float ySize = FillVertical() ? dc.GetLayoutBounds().h - 30 : WRAP_CONTENT; + const Bounds layoutBounds = GetLayoutBounds(dc); + const float ySize = FillVertical() ? layoutBounds.h - 30 : WRAP_CONTENT; - int y = (dc.GetLayoutBounds().h - RootMargins().vert()) * 0.5f + offsetY_; + int y = (layoutBounds.h - RootMargins().vert()) * 0.5f + offsetY_; Centering vCentering = Centering::Vertical; if (alignTop_) { if (GetDeviceOrientation() == DeviceOrientation::Landscape) { @@ -155,12 +156,12 @@ void PopupScreen::CreateViews() { AnchorLayoutParams *anchorParams; // NOTE: We purely use the popup width here to decide the type of layout, instead of the device orientation. - if (dc.GetLayoutBounds().w < popupWidth + 50) { + if (layoutBounds.w < popupWidth + 50) { anchorParams = new AnchorLayoutParams(popupWidth, ySize, 10, y, 10, NONE, vCentering); } else { anchorParams = new AnchorLayoutParams(popupWidth, ySize, - (dc.GetLayoutBounds().w - RootMargins().horiz()) * 0.5, y, NONE, NONE, vCentering | Centering::Horizontal); + (layoutBounds.w - RootMargins().horiz()) * 0.5, y, NONE, NONE, vCentering | Centering::Horizontal); } box_ = new LinearLayout(ORIENT_VERTICAL, anchorParams); diff --git a/Common/UI/ScrollView.cpp b/Common/UI/ScrollView.cpp index e300a52ec9..f060651d11 100644 --- a/Common/UI/ScrollView.cpp +++ b/Common/UI/ScrollView.cpp @@ -295,7 +295,7 @@ void ScrollView::Draw(UIContext &dc) { } // Same at the bottom. - const float y2 = dc.GetLayoutBounds().y2(); + const float y2 = dc.GetLayoutBounds(false).y2(); if (shadows_ && bounds_.y2() < y2 && orientation_ == ORIENT_VERTICAL) { float radius = 20.0f; diff --git a/Common/UI/UIScreen.cpp b/Common/UI/UIScreen.cpp index 0e76c0f93f..3bff6316cf 100644 --- a/Common/UI/UIScreen.cpp +++ b/Common/UI/UIScreen.cpp @@ -200,6 +200,10 @@ void UIScreen::deviceRestored(Draw::DrawContext *draw) { root_->DeviceRestored(draw); } +Bounds UIScreen::GetLayoutBounds(UIContext &dc) const { + return dc.GetLayoutBounds(ignoreBottomInset_); +} + ScreenRenderFlags UIScreen::render(ScreenRenderMode mode) { DoRecreateViews(); diff --git a/Common/UI/UIScreen.h b/Common/UI/UIScreen.h index a6c09202cd..7d5302c449 100644 --- a/Common/UI/UIScreen.h +++ b/Common/UI/UIScreen.h @@ -62,6 +62,8 @@ public: protected: virtual void CreateViews() = 0; + Bounds GetLayoutBounds(UIContext &dc) const; + void RecreateViews() override { recreateViews_ = true; } DeviceOrientation GetDeviceOrientation() const; bool IsOnTop() const; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index d1af8a3377..7459b9f928 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -900,7 +900,8 @@ void VisualMappingScreen::CreateViews() { leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f))); AddStandardBack(leftColumn); - Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds(); + // TODO: Properly use layout instead of querying bounds. + Bounds bounds = GetLayoutBounds(*screenManager()->getUIContext()); // Account for left side. bounds.w -= leftColumnWidth + 10.0f; @@ -1024,7 +1025,7 @@ void VisualMappingScreen::MapNext(bool successive) { HandleKeyMapping(mapping); }, I18NCat::KEYMAPPING); - Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds(); + Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds(false); dialog->SetPopupOffset(psp_->GetPopupOffset() * bounds.h); dialog->SetDelay(successive ? 0.5f : 0.1f); screenManager()->push(dialog); diff --git a/UI/CustomButtonMappingScreen.cpp b/UI/CustomButtonMappingScreen.cpp index a2cab19c47..dd1a77a832 100644 --- a/UI/CustomButtonMappingScreen.cpp +++ b/UI/CustomButtonMappingScreen.cpp @@ -142,7 +142,7 @@ void CustomButtonMappingScreen::CreateDialogViews(UI::ViewGroup *parent) { array[i] = (0x01 == ((g_Config.CustomButton[id_].key >> i) & 0x01)); // TODO: Less hacky layout work - const Bounds layoutBounds = screenManager()->getUIContext()->GetLayoutBounds(); + const Bounds layoutBounds = screenManager()->getUIContext()->GetLayoutBounds(false); leftColumn->Add(new ButtonPreview(g_Config.iTouchButtonStyle == 0 ? customKeyShapes[cfg->shape].i : customKeyShapes[cfg->shape].l, customKeyImages[cfg->image].i, customKeyImages[cfg->image].r, customKeyShapes[cfg->shape].f, customKeyShapes[cfg->shape].r, layoutBounds.x + 62, layoutBounds.y + 102)); diff --git a/UI/DebugOverlay.cpp b/UI/DebugOverlay.cpp index 2804fef75a..7d92fb54fc 100644 --- a/UI/DebugOverlay.cpp +++ b/UI/DebugOverlay.cpp @@ -220,26 +220,27 @@ void DrawFramebufferList(UIContext *ctx, GPUDebugInterface *gpu, const Bounds &b } void DrawControlMapperOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper &controlMapper) { - DrawControlDebug(ctx, controlMapper, ctx->GetLayoutBounds()); + DrawControlDebug(ctx, controlMapper, ctx->GetLayoutBounds(false)); } void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, DebugOverlay overlay) { bool inGame = GetUIState() == UISTATE_INGAME; + const Bounds layoutBounds = ctx->GetLayoutBounds(false); switch (overlay) { case DebugOverlay::DEBUG_STATS: if (inGame) - DrawDebugStats(ctx, ctx->GetLayoutBounds()); + DrawDebugStats(ctx, layoutBounds); break; case DebugOverlay::FRAME_GRAPH: if (inGame) - DrawFrameTimes(ctx, ctx->GetLayoutBounds()); + DrawFrameTimes(ctx, layoutBounds); break; case DebugOverlay::FRAME_TIMING: - DrawFrameTiming(ctx, ctx->GetLayoutBounds()); + DrawFrameTiming(ctx, layoutBounds); break; case DebugOverlay::Audio: - DrawAudioDebugStats(ctx, ctx->GetLayoutBounds()); + DrawAudioDebugStats(ctx, layoutBounds); break; #if !PPSSPP_PLATFORM(UWP) && !PPSSPP_PLATFORM(SWITCH) case DebugOverlay::GPU_PROFILE: @@ -262,7 +263,6 @@ void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, DebugOverlay overlay } } - static const char *CPUCoreAsString(int core) { switch (core) { case 0: return "Interpreter"; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index d27794f6f1..5753795995 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -736,7 +736,7 @@ void TouchTestScreen::axis(const AxisInput &axis) { } void TouchTestScreen::DrawForeground(UIContext &dc) { - Bounds bounds = dc.GetLayoutBounds(); + Bounds bounds = GetLayoutBounds(dc); double now = dc.FrameStartTime(); double delta = now - lastFrameTime_; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 8b987cddb4..a36ef6ad86 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1267,7 +1267,7 @@ void EmuScreen::CreateViews() { TouchControlConfig &touch = g_Config.GetTouchControlsConfig(deviceOrientation); - const Bounds &bounds = screenManager()->getUIContext()->GetLayoutBounds(); + const Bounds &bounds = GetLayoutBounds(*screenManager()->getUIContext()); InitPadLayout(&touch, deviceOrientation, bounds.w, bounds.h); root_ = CreatePadLayout(touch, bounds.w, bounds.h, &pauseTrigger_, &g_controlMapper); @@ -1969,10 +1969,10 @@ void EmuScreen::renderUI() { if (PSP_IsInited()) { if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::CONTROL) { - DrawControlMapperOverlay(ctx, ctx->GetLayoutBounds(), g_controlMapper); + DrawControlMapperOverlay(ctx, GetLayoutBounds(*ctx), g_controlMapper); } if (g_Config.iShowStatusFlags) { - DrawFPS(ctx, ctx->GetLayoutBounds()); + DrawFPS(ctx, GetLayoutBounds(*ctx)); } } diff --git a/UI/GPUDriverTestScreen.cpp b/UI/GPUDriverTestScreen.cpp index b000505964..52274bc0c2 100644 --- a/UI/GPUDriverTestScreen.cpp +++ b/UI/GPUDriverTestScreen.cpp @@ -235,6 +235,7 @@ static_assert(Draw::SEM_TEXCOORD0 == 3, "Semantic shader hardcoded in glsl above GPUDriverTestScreen::GPUDriverTestScreen() { using namespace Draw; + ignoreBottomInset_ = false; } GPUDriverTestScreen::~GPUDriverTestScreen() { @@ -466,7 +467,7 @@ void GPUDriverTestScreen::DiscardTest(UIContext &dc) { // If everything is OK, both the background and the text should be OK. - Bounds layoutBounds = dc.GetLayoutBounds(); + Bounds layoutBounds = GetLayoutBounds(dc); dc.Begin(); dc.SetFontScale(1.0f, 1.0f); @@ -572,7 +573,7 @@ void GPUDriverTestScreen::ShaderTest(UIContext &dc) { rasterNoCull->Release(); } - Bounds layoutBounds = dc.GetLayoutBounds(); + Bounds layoutBounds = GetLayoutBounds(dc); dc.Begin(); dc.SetFontScale(1.0f, 1.0f); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index b86ccfed7f..a2d3d95255 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -419,7 +419,7 @@ void LogoScreen::touch(const TouchInput &touch) { void LogoScreen::DrawForeground(UIContext &dc) { using namespace Draw; - const Bounds &bounds = dc.GetLayoutBounds(); + const Bounds &bounds = GetLayoutBounds(dc); dc.Begin(); diff --git a/UI/MiscScreens.h b/UI/MiscScreens.h index b01175b9ba..407d7b279e 100644 --- a/UI/MiscScreens.h +++ b/UI/MiscScreens.h @@ -96,7 +96,7 @@ enum class AfterLogoScreen { MEMSTICK_SCREEN_INITIAL_SETUP, }; -class LogoScreen : public UIScreen { +class LogoScreen : public UIBaseScreen { public: LogoScreen(AfterLogoScreen afterLogoScreen = AfterLogoScreen::DEFAULT); diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index b034743e56..762e640ca2 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -410,8 +410,7 @@ void OSDOverlayScreen::DrawForeground(UIContext &ui) { // Special case control for now, since it uses the control mapper that's owned by EmuScreen. if (debugOverlay != DebugOverlay::OFF && debugOverlay != DebugOverlay::CONTROL) { - UIContext *uiContext = screenManager()->getUIContext(); - DrawDebugOverlay(uiContext, uiContext->GetLayoutBounds(), debugOverlay); + DrawDebugOverlay(&ui, GetLayoutBounds(ui), debugOverlay); } } diff --git a/UI/OnScreenDisplay.h b/UI/OnScreenDisplay.h index 63991ddb84..976cbc2188 100644 --- a/UI/OnScreenDisplay.h +++ b/UI/OnScreenDisplay.h @@ -50,4 +50,3 @@ public: private: OnScreenMessagesView *osmView_ = nullptr; }; -