Improve button measurements on macOS and Linux #298

Open
opened 2026-04-05 16:19:40 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @yw4z on 3/16/2026

tested on Windows, Linux (debian gnome, mint cinnamon, fedora kde), macOS (Ventura)

MACOS

Text not properly aligned vertically

GetTextExtent and GetMultiLineTextExtent returns a height that includes external leading
On Mac, external leading value is significantly larger than on Windows/Linux due to how CoreText reports font metrics.

Solution: Excluded external leading from calculation to get proper height
Font metrics works on all platforms properly

Before-After Tab buttons
Screenshot 2026-03-17 at 09 59 24

Before-After Flushing volumes button
Screenshot 2026-03-18 at 16 29 07

Before-After Regular buttons
Screenshot 2026-03-18 at 16 30 02

Before-After Print / Slice buttons
Screenshot 2026-03-18 at 16 30 24

LINUX

Misaligned icons

Before-After
Fixed misaligned icons while using compact size
Screenshot-20260317101442

Oversized main tab buttons

Used FromDIP like on most of UI instead em_unit. em unit returns different values on linus (12 to 14) compared to 10 on windows and macOS
Before-After button sizes matched with windows
left ones are windows
Screenshot-20260318161812
Screenshot-20260318161612

FURTHER TESTING

Screenshot-20260318172746

here is what i found included to this PR
• Parameter style doesnt respect max size (fixed in this PR with adding SetMaxSize)
• Multiline texts was not properly centered (fixed in this PR). Calculation made from whole text instead line with max line width

Didnt included to this PR
• SetCenter(false) doesnt use padding on left.
• Padding not applied properly when text ellipsized
• Padding has to applied first to draw rectangle for proper fix but requires a lot of changes

Notes
• Multiline feature is not important much because its not used on code
• SetCenter(false) used only on BBL multi device pages without button background. so issue not visible
• SetVertical() only used on CalibrationWizardPresetPage.cpp

created a test block on preferences to test wxBoxSizer*test_sizer_1 = new wxBoxSizer(wxHORIZONTAL); auto test_btn_1 = new Button(m_parent, _L("Regular")); test_btn_1->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_sizer_1->Add(test_btn_1);
auto test_btn_2 = new Button(m_parent, _L("Test ÜÇĞ with long text"));
test_btn_2->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_sizer_1->Add(test_btn_2, 0, wxLEFT, FromDIP(10));

auto test_btn_3 = new Button(m_parent, _L("CentTest"), "add", 0, 16);
test_btn_3->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_sizer_1->Add(test_btn_3, 0, wxLEFT, FromDIP(10));

auto test_btn_4 = new Button(m_parent, _L("LeftTest"), "add", 0, 16);
test_btn_4->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_btn_4->SetCenter(false);
test_sizer_1->Add(test_btn_4, 0, wxLEFT, FromDIP(10));

g_sizer->Add(test_sizer_1, 0, wxALL, FromDIP(10));

wxBoxSizer*test_sizer_3 = new wxBoxSizer(wxHORIZONTAL);
auto test_btn_11 = new Button(m_parent, _L("Regular with long text"));
test_btn_11->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_sizer_3->Add(test_btn_11);

auto test_btn_21 = new Button(m_parent, _L("Test ÜÇĞ with long text"));
test_btn_21->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_sizer_3->Add(test_btn_21, 0, wxLEFT, FromDIP(10));

auto test_btn_31 = new Button(m_parent, _L("CentTest with long text"), "add", 0, 16);
test_btn_31->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_sizer_3->Add(test_btn_31, 0, wxLEFT, FromDIP(10));

auto test_btn_41 = new Button(m_parent, _L("LeftTest with long text"), "add", 0, 16);
test_btn_41->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_btn_41->SetCenter(false);
test_sizer_3->Add(test_btn_41, 0, wxLEFT, FromDIP(10));

g_sizer->Add(test_sizer_3, 0, wxALL, FromDIP(10));

wxBoxSizer*test_sizer_2 = new wxBoxSizer(wxHORIZONTAL);

wxBoxSizer*test_sizer_5 = new wxBoxSizer(wxHORIZONTAL);
auto test_btn_12 = new Button(m_parent, _L("Regular"));
test_btn_12->SetStyle(ButtonStyle::Regular, ButtonType::Window);
test_sizer_5->Add(test_btn_12);

auto test_btn_22 = new Button(m_parent, _L("Test ÜÇĞ with long text"));
test_btn_22->SetStyle(ButtonStyle::Regular, ButtonType::Window);
test_sizer_5->Add(test_btn_22, 0, wxLEFT, FromDIP(10));

auto test_btn_32 = new Button(m_parent, _L("CentTest"), "add", 0, 16);
test_btn_32->SetStyle(ButtonStyle::Regular, ButtonType::Window);
test_sizer_5->Add(test_btn_32, 0, wxLEFT, FromDIP(10));

auto test_btn_42 = new Button(m_parent, _L("LeftTest"), "add", 0, 16);
test_btn_42->SetStyle(ButtonStyle::Regular, ButtonType::Window);
test_btn_42->SetCenter(false);
test_sizer_5->Add(test_btn_42, 0, wxLEFT, FromDIP(10));

g_sizer->Add(test_sizer_5, 0, wxALL, FromDIP(10));

auto test_btn_5 = new Button(m_parent, _L("NonVertical\nNonIcon"));
test_btn_5->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_btn_5->SetMinSize(FromDIP(wxSize(120,90)));
test_btn_5->SetSize(FromDIP(wxSize(120,90)));
test_sizer_2->Add(test_btn_5);

auto test_btn_6 = new Button(m_parent, _L("Vertical\n& Icon"), "add", 0, 16);
test_btn_6->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_btn_6->SetMinSize(FromDIP(wxSize(120,90)));
test_btn_6->SetSize(FromDIP(wxSize(120,90)));
test_btn_6->SetVertical(true);
test_sizer_2->Add(test_btn_6, 0, wxLEFT, FromDIP(10));

auto test_btn_7 = new Button(m_parent, _L("NonVertical\n& Icon"), "add", 0, 16);
test_btn_7->SetStyle(ButtonStyle::Regular, ButtonType::Parameter);
test_btn_7->SetMinSize(FromDIP(wxSize(120,90)));
test_btn_7->SetSize(FromDIP(wxSize(120,90)));
test_sizer_2->Add(test_btn_7, 0, wxLEFT, FromDIP(10));

g_sizer->Add(test_sizer_2, 0, wxALL, FromDIP(10));
*Originally created by @yw4z on 3/16/2026* tested on Windows, Linux (debian gnome, mint cinnamon, fedora kde), macOS (Ventura) # MACOS ### Text not properly aligned vertically GetTextExtent and GetMultiLineTextExtent returns a height that includes external leading On Mac, external leading value is significantly larger than on Windows/Linux due to how CoreText reports font metrics. **Solution: Excluded external leading from calculation to get proper height** Font metrics works on all platforms properly **Before-After Tab buttons** ![Screenshot 2026-03-17 at 09 59 24](https://github.com/user-attachments/assets/0df5c0e7-e9ae-4d9c-a424-7a72d5d65932) **Before-After Flushing volumes button** ![Screenshot 2026-03-18 at 16 29 07](https://github.com/user-attachments/assets/d7719487-780d-410a-b04a-6630584be9fa) **Before-After Regular buttons** ![Screenshot 2026-03-18 at 16 30 02](https://github.com/user-attachments/assets/e38523f6-2b11-41c4-a6ab-698caacd1f95) **Before-After Print / Slice buttons** ![Screenshot 2026-03-18 at 16 30 24](https://github.com/user-attachments/assets/637c7b8b-0ce5-4b74-9b7e-3c0c1ebd8e1d) # LINUX ### Misaligned icons **Before-After** Fixed misaligned icons while using compact size <img width="264" height="187" alt="Screenshot-20260317101442" src="https://github.com/user-attachments/assets/901490a5-7e8c-4714-b5aa-59e3cc908942" /> ### Oversized main tab buttons Used FromDIP like on most of UI instead em_unit. em unit returns different values on linus (12 to 14) compared to 10 on windows and macOS **Before-After button sizes matched with windows** left ones are windows <img width="437" height="102" alt="Screenshot-20260318161812" src="https://github.com/user-attachments/assets/af271dfc-0a09-4259-bb5d-efa7b8ee83dd" /> <img width="364" height="90" alt="Screenshot-20260318161612" src="https://github.com/user-attachments/assets/e83258ca-d254-4b35-8cdc-920734406acc" /> # FURTHER TESTING <img width="537" height="260" alt="Screenshot-20260318172746" src="https://github.com/user-attachments/assets/b67f5eec-4e47-4ed7-9201-1599f5523588" /> here is what i found included to this PR • Parameter style doesnt respect max size (fixed in this PR with adding SetMaxSize) • Multiline texts was not properly centered (fixed in this PR). Calculation made from whole text instead line with max line width Didnt included to this PR • SetCenter(false) doesnt use padding on left. • Padding not applied properly when text ellipsized • Padding has to applied first to draw rectangle for **proper fix but requires a lot of changes** Notes • Multiline feature is not important much because its not used on code • SetCenter(false) used only on BBL multi device pages without button background. so issue not visible • SetVertical() only used on CalibrationWizardPresetPage.cpp <details><summary>created a test block on preferences to test</summary> wxBoxSizer*test_sizer_1 = new wxBoxSizer(wxHORIZONTAL); auto test_btn_1 = new Button(m_parent, _L("Regular")); test_btn_1->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_sizer_1->Add(test_btn_1); auto test_btn_2 = new Button(m_parent, _L("Test ÜÇĞ with long text")); test_btn_2->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_sizer_1->Add(test_btn_2, 0, wxLEFT, FromDIP(10)); auto test_btn_3 = new Button(m_parent, _L("CentTest"), "add", 0, 16); test_btn_3->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_sizer_1->Add(test_btn_3, 0, wxLEFT, FromDIP(10)); auto test_btn_4 = new Button(m_parent, _L("LeftTest"), "add", 0, 16); test_btn_4->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_btn_4->SetCenter(false); test_sizer_1->Add(test_btn_4, 0, wxLEFT, FromDIP(10)); g_sizer->Add(test_sizer_1, 0, wxALL, FromDIP(10)); wxBoxSizer*test_sizer_3 = new wxBoxSizer(wxHORIZONTAL); auto test_btn_11 = new Button(m_parent, _L("Regular with long text")); test_btn_11->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_sizer_3->Add(test_btn_11); auto test_btn_21 = new Button(m_parent, _L("Test ÜÇĞ with long text")); test_btn_21->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_sizer_3->Add(test_btn_21, 0, wxLEFT, FromDIP(10)); auto test_btn_31 = new Button(m_parent, _L("CentTest with long text"), "add", 0, 16); test_btn_31->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_sizer_3->Add(test_btn_31, 0, wxLEFT, FromDIP(10)); auto test_btn_41 = new Button(m_parent, _L("LeftTest with long text"), "add", 0, 16); test_btn_41->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_btn_41->SetCenter(false); test_sizer_3->Add(test_btn_41, 0, wxLEFT, FromDIP(10)); g_sizer->Add(test_sizer_3, 0, wxALL, FromDIP(10)); wxBoxSizer*test_sizer_2 = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer*test_sizer_5 = new wxBoxSizer(wxHORIZONTAL); auto test_btn_12 = new Button(m_parent, _L("Regular")); test_btn_12->SetStyle(ButtonStyle::Regular, ButtonType::Window); test_sizer_5->Add(test_btn_12); auto test_btn_22 = new Button(m_parent, _L("Test ÜÇĞ with long text")); test_btn_22->SetStyle(ButtonStyle::Regular, ButtonType::Window); test_sizer_5->Add(test_btn_22, 0, wxLEFT, FromDIP(10)); auto test_btn_32 = new Button(m_parent, _L("CentTest"), "add", 0, 16); test_btn_32->SetStyle(ButtonStyle::Regular, ButtonType::Window); test_sizer_5->Add(test_btn_32, 0, wxLEFT, FromDIP(10)); auto test_btn_42 = new Button(m_parent, _L("LeftTest"), "add", 0, 16); test_btn_42->SetStyle(ButtonStyle::Regular, ButtonType::Window); test_btn_42->SetCenter(false); test_sizer_5->Add(test_btn_42, 0, wxLEFT, FromDIP(10)); g_sizer->Add(test_sizer_5, 0, wxALL, FromDIP(10)); auto test_btn_5 = new Button(m_parent, _L("NonVertical\nNonIcon")); test_btn_5->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_btn_5->SetMinSize(FromDIP(wxSize(120,90))); test_btn_5->SetSize(FromDIP(wxSize(120,90))); test_sizer_2->Add(test_btn_5); auto test_btn_6 = new Button(m_parent, _L("Vertical\n& Icon"), "add", 0, 16); test_btn_6->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_btn_6->SetMinSize(FromDIP(wxSize(120,90))); test_btn_6->SetSize(FromDIP(wxSize(120,90))); test_btn_6->SetVertical(true); test_sizer_2->Add(test_btn_6, 0, wxLEFT, FromDIP(10)); auto test_btn_7 = new Button(m_parent, _L("NonVertical\n& Icon"), "add", 0, 16); test_btn_7->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); test_btn_7->SetMinSize(FromDIP(wxSize(120,90))); test_btn_7->SetSize(FromDIP(wxSize(120,90))); test_sizer_2->Add(test_btn_7, 0, wxLEFT, FromDIP(10)); g_sizer->Add(test_sizer_2, 0, wxALL, FromDIP(10)); </details>
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/OrcaSlicer#298