From 54c5113b797326043f199ddc4cfd683750866df5 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Tue, 26 Jul 2022 18:47:36 +0800 Subject: [PATCH] FIX: recalc textsize after set font Change-Id: Ic4717ffd5b418fa7030659e3e684b0868cca2c61 --- src/slic3r/GUI/Widgets/SpinInput.cpp | 8 +++----- src/slic3r/GUI/Widgets/TextInput.cpp | 21 +++++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/Widgets/SpinInput.cpp b/src/slic3r/GUI/Widgets/SpinInput.cpp index 9fa0727b8..52a1eeb52 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.cpp +++ b/src/slic3r/GUI/Widgets/SpinInput.cpp @@ -48,9 +48,10 @@ SpinInput::SpinInput(wxWindow * parent, wxWindow::SetLabel(label); state_handler.attach({&border_color, &text_color, &background_color}); state_handler.update_binds(); - text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 5}, wxDefaultSize, + text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_DIGITS)); text_ctrl->SetFont(Label::Body_14); + text_ctrl->SetInitialSize(text_ctrl->GetBestSize()); text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) { e.SetId(GetId()); ProcessEventLocally(e); @@ -199,10 +200,7 @@ void SpinInput::messureSize() { wxSize size = GetSize(); wxSize textSize = text_ctrl->GetSize(); -#ifdef __WXOSX__ - textSize.y -= 3; // TODO: -#endif - int h = textSize.y * 24 / 14; + int h = textSize.y + 8; if (size.y < h) { size.y = h; SetSize(size); diff --git a/src/slic3r/GUI/Widgets/TextInput.cpp b/src/slic3r/GUI/Widgets/TextInput.cpp index 43e822f98..82c90b171 100644 --- a/src/slic3r/GUI/Widgets/TextInput.cpp +++ b/src/slic3r/GUI/Widgets/TextInput.cpp @@ -61,13 +61,14 @@ void TextInput::Create(wxWindow * parent, { text_ctrl = nullptr; wxWindow::Create(parent, wxID_ANY, pos, size, style); - + wxWindow::SetLabel(label); style &= ~wxRIGHT; state_handler.attach({&border_color, &text_color, &background_color}); state_handler.update_binds(); - text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {5, 5}, wxDefaultSize, - style | wxBORDER_NONE); + text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE); + text_ctrl->SetFont(Label::Body_14); + text_ctrl->SetInitialSize(text_ctrl->GetBestSize()); text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) { e.SetId(GetId()); ProcessEventLocally(e); @@ -91,7 +92,6 @@ void TextInput::Create(wxWindow * parent, ProcessEventLocally(e); }); text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu - text_ctrl->SetFont(Label::Body_14); if (!icon.IsEmpty()) { this->icon = ScalableBitmap(this, icon.ToStdString(), 16); } @@ -180,10 +180,10 @@ void TextInput::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (align_right) textPos.x += labelSize.x; if (text_ctrl) { - wxSize textSize = text_ctrl->GetSize(); - textSize.x = size.x - textPos.x - labelSize.x - 10; - text_ctrl->SetSize(textSize); - text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2}); + wxSize textSize = text_ctrl->GetSize(); + textSize.x = size.x - textPos.x - labelSize.x - 10; + text_ctrl->SetSize(textSize); + text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2}); } } @@ -245,10 +245,7 @@ void TextInput::messureSize() wxClientDC dc(this); labelSize = dc.GetTextExtent(wxWindow::GetLabel()); wxSize textSize = text_ctrl->GetSize(); -#ifdef __WXOSX__ - textSize.y -= 3; // TODO: -#endif - int h = textSize.y * 24 / 14; + int h = textSize.y + 8; if (size.y < h) { size.y = h; }