Fix state of fullscreen button on main screen

This commit is contained in:
Henrik Rydgård
2026-03-05 00:58:43 +01:00
parent ac437ff05d
commit cbab0ce203
3 changed files with 33 additions and 16 deletions
+24 -10
View File
@@ -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();
}
}
+4
View File
@@ -562,6 +562,9 @@ public:
void SetImageID(ImageID imageID) {
imageID_ = imageID;
}
void SetImageIDFunc(std::function<ImageID()> func) {
imageFunc_ = func;
}
void SetIgnoreText(bool ignore) {
ignoreText_ = ignore;
}
@@ -574,6 +577,7 @@ private:
Style style_;
std::string text_;
ImageID imageID_;
std::function<ImageID()> imageFunc_;
int paddingW_ = 16;
int paddingH_ = 8;
float scale_ = 1.0f;
+5 -6
View File
@@ -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);