From c634e73885b91d1995aedf0cb36696dc2b9fb736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 9 Mar 2026 16:41:07 +0100 Subject: [PATCH] Fix more centering and sizing bugs --- Common/UI/PopupScreens.cpp | 2 +- Common/UI/PopupScreens.h | 2 +- Common/UI/View.cpp | 20 ++++++++++++++++++-- Common/UI/View.h | 2 ++ UI/SystemInfoScreen.cpp | 7 ++++--- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index c1aed0412e..873fd49a43 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -160,7 +160,7 @@ void PopupScreen::CreateViews() { 10, y, 10, NONE, vCentering); } else { anchorParams = new AnchorLayoutParams(popupWidth, ySize, - dc.GetLayoutBounds().centerX(), y, NONE, NONE, vCentering | Centering::Horizontal); + (dc.GetLayoutBounds().w - RootMargins().horiz()) * 0.5, y, NONE, NONE, vCentering | Centering::Horizontal); } box_ = new LinearLayout(ORIENT_VERTICAL, anchorParams); diff --git a/Common/UI/PopupScreens.h b/Common/UI/PopupScreens.h index b0b3a330ff..1134995409 100644 --- a/Common/UI/PopupScreens.h +++ b/Common/UI/PopupScreens.h @@ -43,7 +43,7 @@ public: notificationLevel_ = noticeLevel; notificationString_ = str; } - virtual UI::Margins RootMargins() const { return UI::Margins(24); } + virtual UI::Margins RootMargins() const { return UI::Margins(12, 24); } protected: virtual bool FillVertical() const { return false; } diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index c05fc1c794..fb55294f08 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -386,7 +386,7 @@ void StickyChoice::FocusChanged(int focusFlags) { Item::Item(LayoutParams *layoutParams) : InertView(layoutParams) { if (!layoutParams) { layoutParams_->width = FILL_PARENT; - layoutParams_->height = ITEM_HEIGHT; + layoutParams_->height = WRAP_CONTENT; } } @@ -545,6 +545,22 @@ InfoItem::InfoItem(std::string_view text, std::string_view rightText, LayoutPara // We set the colors later once we have a UIContext. } +void InfoItem::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const { + float w1, h1, w2, h2; + dc.MeasureText(dc.GetTheme().uiFont, 1.0f, 1.0f, text_, &w1, &h1, 0); + + if (horiz.type == MeasureSpecType::AT_MOST) { + float availableWidth = horiz.size - w1 - 24; + dc.MeasureTextRect(dc.GetTheme().uiFont, 1.0f, 1.0f, rightText_, availableWidth, &w2, &h2, FLAG_WRAP_TEXT); + } else { + dc.MeasureText(dc.GetTheme().uiFont, 1.0f, 1.0f, rightText_, &w2, &h2, 0); + } + + // TODO: Make this more exact. + w = 24 + w1 + w2; + h = std::max(std::max(h1, h2), ITEM_HEIGHT); +} + void InfoItem::Draw(UIContext &dc) { Item::Draw(dc); @@ -573,7 +589,7 @@ std::string InfoItem::DescribeText() const { ItemHeader::ItemHeader(std::string_view text, LayoutParams *layoutParams) : Item(layoutParams), text_(text) { layoutParams_->width = FILL_PARENT; - layoutParams_->height = 40; + layoutParams_->height = 44; } void ItemHeader::Draw(UIContext &dc) { diff --git a/Common/UI/View.h b/Common/UI/View.h index 5064e02c57..adc3febb26 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -834,6 +834,8 @@ public: void SetRightText(std::string_view text) { rightText_ = text; } +protected: + void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const; private: std::string text_; diff --git a/UI/SystemInfoScreen.cpp b/UI/SystemInfoScreen.cpp index dcaed401b9..7d315e4d9c 100644 --- a/UI/SystemInfoScreen.cpp +++ b/UI/SystemInfoScreen.cpp @@ -77,12 +77,13 @@ void SystemInfoScreen::CreateTabs() { auto si = GetI18NCategory(I18NCat::SYSINFO); - AddTab("Device Info", si->T("Device Info"), [this](UI::LinearLayout *parent) { - CreateDeviceInfoTab(parent); - }); AddTab("Storage", si->T("Storage"), [this](UI::LinearLayout *parent) { CreateStorageTab(parent); }); + + AddTab("Device Info", si->T("Device Info"), [this](UI::LinearLayout *parent) { + CreateDeviceInfoTab(parent); + }); AddTab("DevSystemInfoBuildConfig", si->T("Build Config"), [this](UI::LinearLayout *parent) { CreateBuildConfigTab(parent); });