FIX: recalc textsize after set font

Change-Id: Ic4717ffd5b418fa7030659e3e684b0868cca2c61
This commit is contained in:
chunmao.guo 2022-07-26 18:47:36 +08:00 committed by Lane.Wei
parent 405444f042
commit 54c5113b79
2 changed files with 12 additions and 17 deletions

View File

@ -48,9 +48,10 @@ SpinInput::SpinInput(wxWindow * parent,
wxWindow::SetLabel(label); wxWindow::SetLabel(label);
state_handler.attach({&border_color, &text_color, &background_color}); state_handler.attach({&border_color, &text_color, &background_color});
state_handler.update_binds(); 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)); style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_DIGITS));
text_ctrl->SetFont(Label::Body_14); text_ctrl->SetFont(Label::Body_14);
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) { text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) {
e.SetId(GetId()); e.SetId(GetId());
ProcessEventLocally(e); ProcessEventLocally(e);
@ -199,10 +200,7 @@ void SpinInput::messureSize()
{ {
wxSize size = GetSize(); wxSize size = GetSize();
wxSize textSize = text_ctrl->GetSize(); wxSize textSize = text_ctrl->GetSize();
#ifdef __WXOSX__ int h = textSize.y + 8;
textSize.y -= 3; // TODO:
#endif
int h = textSize.y * 24 / 14;
if (size.y < h) { if (size.y < h) {
size.y = h; size.y = h;
SetSize(size); SetSize(size);

View File

@ -61,13 +61,14 @@ void TextInput::Create(wxWindow * parent,
{ {
text_ctrl = nullptr; text_ctrl = nullptr;
wxWindow::Create(parent, wxID_ANY, pos, size, style); wxWindow::Create(parent, wxID_ANY, pos, size, style);
wxWindow::SetLabel(label); wxWindow::SetLabel(label);
style &= ~wxRIGHT; style &= ~wxRIGHT;
state_handler.attach({&border_color, &text_color, &background_color}); state_handler.attach({&border_color, &text_color, &background_color});
state_handler.update_binds(); state_handler.update_binds();
text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {5, 5}, wxDefaultSize, text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE);
style | wxBORDER_NONE); text_ctrl->SetFont(Label::Body_14);
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) { text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) {
e.SetId(GetId()); e.SetId(GetId());
ProcessEventLocally(e); ProcessEventLocally(e);
@ -91,7 +92,6 @@ void TextInput::Create(wxWindow * parent,
ProcessEventLocally(e); ProcessEventLocally(e);
}); });
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
text_ctrl->SetFont(Label::Body_14);
if (!icon.IsEmpty()) { if (!icon.IsEmpty()) {
this->icon = ScalableBitmap(this, icon.ToStdString(), 16); 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) if (align_right)
textPos.x += labelSize.x; textPos.x += labelSize.x;
if (text_ctrl) { if (text_ctrl) {
wxSize textSize = text_ctrl->GetSize(); wxSize textSize = text_ctrl->GetSize();
textSize.x = size.x - textPos.x - labelSize.x - 10; textSize.x = size.x - textPos.x - labelSize.x - 10;
text_ctrl->SetSize(textSize); text_ctrl->SetSize(textSize);
text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2}); text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2});
} }
} }
@ -245,10 +245,7 @@ void TextInput::messureSize()
wxClientDC dc(this); wxClientDC dc(this);
labelSize = dc.GetTextExtent(wxWindow::GetLabel()); labelSize = dc.GetTextExtent(wxWindow::GetLabel());
wxSize textSize = text_ctrl->GetSize(); wxSize textSize = text_ctrl->GetSize();
#ifdef __WXOSX__ int h = textSize.y + 8;
textSize.y -= 3; // TODO:
#endif
int h = textSize.y * 24 / 14;
if (size.y < h) { if (size.y < h) {
size.y = h; size.y = h;
} }