From 6148ba16b33d462ccd0fe8a401516893fa54438d Mon Sep 17 00:00:00 2001 From: SoftFever Date: Thu, 26 Mar 2026 16:05:58 +0800 Subject: [PATCH] Fix GTK negative content width warnings for bitmap toggle buttons On Linux/GTK, CheckBox, RadioBox, and SwitchButton set their size to exactly the bitmap size (18x18 or 16x16), but GTK's internal CSS padding requires additional space, resulting in negative content width warnings. Use GetBestSize() on GTK to account for theme padding. --- src/slic3r/GUI/Widgets/CheckBox.cpp | 19 +++++++++++++++++-- src/slic3r/GUI/Widgets/RadioBox.cpp | 19 +++++++++++++++++-- src/slic3r/GUI/Widgets/SwitchButton.cpp | 9 ++++++++- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/Widgets/CheckBox.cpp b/src/slic3r/GUI/Widgets/CheckBox.cpp index 5c3baa2fc1..4e03f42187 100644 --- a/src/slic3r/GUI/Widgets/CheckBox.cpp +++ b/src/slic3r/GUI/Widgets/CheckBox.cpp @@ -24,9 +24,16 @@ CheckBox::CheckBox(wxWindow *parent, int id) Bind(wxEVT_ENTER_WINDOW, &CheckBox::updateBitmap, this); Bind(wxEVT_LEAVE_WINDOW, &CheckBox::updateBitmap, this); #endif + update(); +#ifdef __WXGTK__ + wxSize bestSize = GetBestSize(); + bestSize.IncTo(m_on.GetBmpSize()); + SetSize(bestSize); + SetMinSize(bestSize); +#else SetSize(m_on.GetBmpSize()); SetMinSize(m_on.GetBmpSize()); - update(); +#endif } void CheckBox::SetValue(bool value) @@ -54,8 +61,16 @@ void CheckBox::Rescale() m_on_focused.msw_rescale(); m_half_focused.msw_rescale(); m_off_focused.msw_rescale(); + update(); +#ifdef __WXGTK__ + wxSize bestSize = GetBestSize(); + bestSize.IncTo(m_on.GetBmpSize()); + SetSize(bestSize); + SetMinSize(bestSize); +#else SetSize(m_on.GetBmpSize()); - update(); + SetMinSize(m_on.GetBmpSize()); +#endif } void CheckBox::update() diff --git a/src/slic3r/GUI/Widgets/RadioBox.cpp b/src/slic3r/GUI/Widgets/RadioBox.cpp index 88427b0304..a8a1d8a1ef 100644 --- a/src/slic3r/GUI/Widgets/RadioBox.cpp +++ b/src/slic3r/GUI/Widgets/RadioBox.cpp @@ -13,9 +13,16 @@ RadioBox::RadioBox(wxWindow *parent) // SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); if (parent) SetBackgroundColour(parent->GetBackgroundColour()); // Bind(wxEVT_TOGGLEBUTTON, [this](auto& e) { update(); e.Skip(); }); + update(); +#ifdef __WXGTK__ + wxSize bestSize = GetBestSize(); + bestSize.IncTo(m_on.GetBmpSize()); + SetSize(bestSize); + SetMinSize(bestSize); +#else SetSize(m_on.GetBmpSize()); SetMinSize(m_on.GetBmpSize()); - update(); +#endif } void RadioBox::SetValue(bool value) @@ -34,8 +41,16 @@ void RadioBox::Rescale() { m_on.msw_rescale(); m_off.msw_rescale(); - SetSize(m_on.GetBmpSize()); update(); +#ifdef __WXGTK__ + wxSize bestSize = GetBestSize(); + bestSize.IncTo(m_on.GetBmpSize()); + SetSize(bestSize); + SetMinSize(bestSize); +#else + SetSize(m_on.GetBmpSize()); + SetMinSize(m_on.GetBmpSize()); +#endif } void RadioBox::update() { diff --git a/src/slic3r/GUI/Widgets/SwitchButton.cpp b/src/slic3r/GUI/Widgets/SwitchButton.cpp index 1c88d1afb0..3aafa0fbc1 100644 --- a/src/slic3r/GUI/Widgets/SwitchButton.cpp +++ b/src/slic3r/GUI/Widgets/SwitchButton.cpp @@ -180,8 +180,15 @@ void SwitchButton::Rescale() (i == 0 ? m_off : m_on).bmp() = bmp; } } - SetSize(m_on.GetBmpSize()); update(); +#ifdef __WXGTK__ + wxSize bestSize = GetBestSize(); + bestSize.IncTo(m_on.GetBmpSize()); + SetSize(bestSize); + SetMinSize(bestSize); +#else + SetSize(m_on.GetBmpSize()); +#endif } void SwitchButton::update()