Fix UI alignment problem on pause screen

This commit is contained in:
Henrik Rydgård committed 2025-11-04 11:06:06 +01:00
1 parent f8d1699552
commit e2e4ceb525
7 files changed
+24 -18

No files matched your search

+5 -1
View File
@@ -100,7 +100,7 @@ bool IsFocusMovementEnabled() {
return focusMovementEnabled;
}
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset) {
void LayoutViewHierarchy(const UIContext &dc, const UI::Margins &rootMargins, ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset) {
Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds(ignoreBottomInset);
MeasureSpec horiz(EXACTLY, rootBounds.w);
@@ -109,6 +109,10 @@ void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets
// Two phases - measure contents, layout.
root->Measure(dc, horiz, vert);
// Root has a specified size. Set it, then let root layout all its children.
rootBounds.x += rootMargins.left;
rootBounds.y += rootMargins.top;
rootBounds.w -= rootMargins.right;
rootBounds.h -= rootMargins.bottom;
root->SetBounds(rootBounds);
root->Layout();
}
+3 -1
View File
@@ -8,6 +8,8 @@
namespace UI {
struct Margins;
// The ONLY global is the currently focused item.
// Can be and often is null.
void EnableFocusMovement(bool enable);
@@ -22,7 +24,7 @@ DialogResult DispatchEvents();
class ViewGroup;
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset);
void LayoutViewHierarchy(const UIContext &dc, const UI::Margins &rootMargins, UI::ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset);
DialogResult UpdateViewHierarchy(ViewGroup *root);
enum class KeyEventResult {
+2 -2
View File
@@ -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_, ignoreBottomInset_);
UI::LayoutViewHierarchy(*screenManager()->getUIContext(), RootMargins(), 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_, ignoreBottomInset_);
UI::LayoutViewHierarchy(uiContext, RootMargins(), root_, ignoreInsets_, ignoreBottomInset_);
}
uiContext.PushTransform({translation_, scale_, alpha_});
+2
View File
@@ -57,6 +57,8 @@ public:
void OnCancel(UI::EventParams &e);
void OnBack(UI::EventParams &e);
virtual UI::Margins RootMargins() const { return UI::Margins(0); }
protected:
virtual void CreateViews() = 0;
+1 -1
View File
@@ -1942,7 +1942,7 @@ void EmuScreen::renderUI() {
thin3d->SetViewport(viewport);
if (root_) {
UI::LayoutViewHierarchy(*ctx, root_, false, false);
UI::LayoutViewHierarchy(*ctx, RootMargins(), root_, false, false);
root_->Draw(*ctx);
}
+10 -13
View File
@@ -390,6 +390,16 @@ void GamePauseScreen::CreateSavestateControls(UI::LinearLayout *leftColumnItems,
}
}
UI::Margins GamePauseScreen::RootMargins() const {
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) {
// Add some top margin on mobile so it isn't too close to the status bar, as we place buttons
// very close to the top of the screen.
return UI::Margins(0, 30, 0, 0);
} else {
return UI::Margins(0);
}
}
void GamePauseScreen::CreateViews() {
using namespace UI;
@@ -411,12 +421,8 @@ void GamePauseScreen::CreateViews() {
LinearLayout *leftColumnItems = new LinearLayoutList(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
leftColumn->Add(leftColumnItems);
// If no other banner added, we want to add a spacer to move the Save/Load state buttons down a bit.
bool bannerAdded = false;
leftColumnItems->SetSpacing(5.0f);
if (Achievements::IsActive()) {
bannerAdded = true;
leftColumnItems->Add(new GameAchievementSummaryView());
char buf[512];
@@ -427,7 +433,6 @@ void GamePauseScreen::CreateViews() {
}
if (IsNetworkConnected()) {
bannerAdded = true;
leftColumnItems->Add(new NoticeView(NoticeLevel::INFO, nw->T("Network connected"), ""));
const InfraDNSConfig &dnsConfig = GetInfraDNSConfig();
@@ -474,7 +479,6 @@ void GamePauseScreen::CreateViews() {
if (showSavestateControls) {
if (PSP_CoreParameter().compat.flags().SaveStatesNotRecommended) {
bannerAdded = true;
LinearLayout *horiz = new LinearLayout(ORIENT_HORIZONTAL);
leftColumnItems->Add(horiz);
horiz->Add(new NoticeView(NoticeLevel::WARN, pa->T("Using save states is not recommended in this game"), "", new LinearLayoutParams(1.0f)));
@@ -482,13 +486,6 @@ void GamePauseScreen::CreateViews() {
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/docs/troubleshooting/save-state-time-warps");
});
}
if (!bannerAdded && System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) {
// Enough so that it's possible to click the save/load buttons of Save 1 without activating
// a pulldown on Android for example.
leftColumnItems->Add(new Spacer(30.0f));
}
CreateSavestateControls(leftColumnItems, portrait);
} else {
// Let's show the active challenges.
+1
View File
@@ -40,6 +40,7 @@ protected:
void CreateViews() override;
void update() override;
void CallbackDeleteConfig(bool yes);
UI::Margins RootMargins() const override;
private:
void CreateSavestateControls(UI::LinearLayout *viewGroup, bool vertical);