Keep extruder switch button padding after a DPI change

This commit is contained in:
SoftFever
2026-10-10 02:45:18 +08:00
parent 3755618146
commit bef49a330b
3 changed files with 12 additions and 8 deletions
+3 -3
View File
@@ -8456,11 +8456,11 @@ void Tab::update_extruder_variants(int extruder_id, bool reload)
int item_n = options.empty() ? 0 : options.size();
if (m_type == Preset::TYPE_PRINTER){ // we are on printer settings dialog and larger padding can be used
int h_pad = item_n > 14 ? 6 : item_n > 12 ? 8 : item_n > 10 ? 16 : item_n > 8 ? 20 : item_n > 6 ? 24 : (item_n > 4 ? 36 : (item_n > 2 ? 48 : 64));
m_extruder_switch->SetButtonPadding(FromDIP(wxSize(h_pad,3)));
m_extruder_switch->SetButtonPadding(wxSize(h_pad, 3));
}
else {
int h_pad = item_n > 6 ? 6 : (item_n > 4 ? 10 : (item_n > 2 ? 20 : 36));
m_extruder_switch->SetButtonPadding(FromDIP(wxSize(h_pad,3)));
m_extruder_switch->SetButtonPadding(wxSize(h_pad, 3));
}
int selection_index;
@@ -8490,7 +8490,7 @@ void Tab::update_extruder_variants(int extruder_id, bool reload)
m_variant_combo->SetOptions(options);
int item_n = options.empty() ? 0 : options.size();
int h_pad = item_n > 6 ? 6 : (item_n > 4 ? 8 : (item_n > 2 ? 20 : 36));
m_variant_combo->SetButtonPadding(FromDIP(wxSize(h_pad,3)));
m_variant_combo->SetButtonPadding(wxSize(h_pad, 3));
if (!options.empty())
m_variant_combo->SetSelection(selection < 0 || selection >= (int) options.size() ? 0 : selection);
+6 -4
View File
@@ -662,7 +662,7 @@ MultiSwitchButton::MultiSwitchButton(wxWindow *parent, wxWindowID id, const wxPo
std::make_pair(0xF1754E, (int) StateColor::NotChecked),
std::make_pair(0xFFFFFE, (int) StateColor::Normal)))
, m_button_radius(10.0)
, m_button_padding(FromDIP(wxSize(11, 3)))
, m_button_padding(11, 3)
{
SetCornerRadius(m_button_radius);
SetBorderWidth(0);
@@ -785,7 +785,7 @@ int MultiSwitchButton::AppendOption(const wxString &option, void *clientData)
btn->SetBorderColor(m_bg_color);
btn->SetTextColor(m_text_color);
btn->SetCornerRadius(m_button_radius);
btn->SetPaddingSize(m_button_padding);
btn->SetPaddingSize(FromDIP(m_button_padding));
btn->SetClientData(clientData);
btns.push_back(btn);
@@ -908,7 +908,7 @@ void MultiSwitchButton::SetButtonPadding(const wxSize &padding)
{
m_button_padding = padding;
for (auto *btn : btns)
btn->SetPaddingSize(padding);
btn->SetPaddingSize(FromDIP(padding));
update_scroll_range();
Layout();
Refresh();
@@ -923,8 +923,10 @@ void MultiSwitchButton::SetModified(int index, bool modified){
void MultiSwitchButton::Rescale()
{
for (auto *btn : btns)
for (auto *btn : btns) {
btn->SetPaddingSize(FromDIP(m_button_padding));
btn->Rescale();
}
// Rescaling can change how the labels measure, and the scrollbar range follows the buttons.
update_scroll_range();
}
+3 -1
View File
@@ -172,6 +172,8 @@ public:
}
void SetModified(int index, bool modified);
void SetButtonCornerRadius(double radius);
// Padding around each button's label, in DIP. The switch converts it for the current DPI when it
// applies it, and again in Rescale().
void SetButtonPadding(const wxSize &padding);
// Keep the switch exactly as wide as the buttons need instead of letting the layout stretch it.
@@ -208,7 +210,7 @@ private:
StateColor m_br_color_modified;
StateColor m_fg_color_modified;
double m_button_radius;
wxSize m_button_padding;
wxSize m_button_padding; // in DIP
};
#endif // !slic3r_GUI_SwitchButton_hpp_