From cbab0ce203e31a9fd4dec199d16009d5f73fd4a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 5 Mar 2026 00:58:43 +0100 Subject: [PATCH] Fix state of fullscreen button on main screen --- Common/UI/View.cpp | 34 ++++++++++++++++++++++++---------- Common/UI/View.h | 4 ++++ UI/MainScreen.cpp | 11 +++++------ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 8cc84f4925..b2f3dac943 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -851,8 +851,15 @@ bool BitCheckBox::Toggled() const { } void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const { - if (imageID_.isValid()) { - dc.Draw()->GetAtlas()->measureImage(imageID_, &w, &h); + ImageID imageId; + if (imageFunc_) { + imageId = imageFunc_(); + } else { + imageId = imageID_; + } + + if (imageId.isValid()) { + dc.Draw()->GetAtlas()->measureImage(imageId, &w, &h); } else { w = 0.0f; h = 0.0f; @@ -864,7 +871,7 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const dc.MeasureText(dc.GetTheme().uiFont, 1.0f, 1.0f, text_, &width, &height); w += width; - if (imageID_.isValid()) { + if (imageId.isValid()) { w += paddingW_; } h = std::max(h, height); @@ -902,19 +909,26 @@ void Button::Draw(UIContext &dc) { tw *= scale_; th *= scale_; - if (tw > bounds_.w || imageID_.isValid()) { + ImageID imageId; + if (imageFunc_) { + imageId = imageFunc_(); + } else { + imageId = imageID_; + } + + if (tw > bounds_.w || imageId.isValid()) { dc.PushScissor(bounds_); } dc.SetFontStyle(dc.GetTheme().uiFont); dc.SetFontScale(scale_, scale_); - if (imageID_.isValid() && (ignoreText_ || text_.empty())) { - dc.Draw()->DrawImage(imageID_, bounds_.centerX(), bounds_.centerY(), scale_, style.fgColor, ALIGN_CENTER); + if (imageId.isValid() && (ignoreText_ || text_.empty())) { + dc.Draw()->DrawImage(imageId, bounds_.centerX(), bounds_.centerY(), scale_, style.fgColor, ALIGN_CENTER); } else if (!text_.empty()) { float textX = bounds_.centerX(); - if (imageID_.isValid()) { - const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(imageID_); + if (imageId.isValid()) { + const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(imageId); if (img) { - dc.Draw()->DrawImage(imageID_, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); + dc.Draw()->DrawImage(imageId, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); textX += img->w / 2.0f; } } @@ -922,7 +936,7 @@ void Button::Draw(UIContext &dc) { } dc.SetFontScale(1.0f, 1.0f); - if (tw > bounds_.w || imageID_.isValid()) { + if (tw > bounds_.w || imageId.isValid()) { dc.PopScissor(); } } diff --git a/Common/UI/View.h b/Common/UI/View.h index 793ac39e1d..94077ee92c 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -562,6 +562,9 @@ public: void SetImageID(ImageID imageID) { imageID_ = imageID; } + void SetImageIDFunc(std::function func) { + imageFunc_ = func; + } void SetIgnoreText(bool ignore) { ignoreText_ = ignore; } @@ -574,6 +577,7 @@ private: Style style_; std::string text_; ImageID imageID_; + std::function imageFunc_; int paddingW_ = 16; int paddingH_ = 8; float scale_ = 1.0f; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 36b1e0c7ab..be0ba46d06 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1456,16 +1456,15 @@ void MainScreen::CreateViews() { ViewGroup *logo = new LogoView(false, new LinearLayoutParams(FILL_PARENT, 80.0f)); #if !defined(MOBILE_DEVICE) auto gr = GetI18NCategory(I18NCat::GRAPHICS); - ImageID icon(g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN"); - UI::Button *fullscreenButton = logo->Add(new Button("", icon, new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, Centering::None))); + Button *fullscreenButton = logo->Add(new Button("", ImageID(), new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, Centering::None))); fullscreenButton->SetIgnoreText(true); - fullscreenButton->OnClick.Add([fullscreenButton](UI::EventParams &e) { - if (fullscreenButton) { - fullscreenButton->SetImageID(ImageID(!g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN")); - } + fullscreenButton->OnClick.Add([this](UI::EventParams &e) { g_Config.bFullScreen = !g_Config.bFullScreen; System_ApplyFullscreenState(); }); + fullscreenButton->SetImageIDFunc([this]() { + return g_Config.bFullScreen ? ImageID("I_RESTORE") : ImageID("I_FULLSCREEN"); + }); #endif rightColumnItems->Add(logo);