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);
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);

View File

@ -66,8 +66,9 @@ void TextInput::Create(wxWindow * parent,
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);
}
@ -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;
}