From 7a5bca3c301773e646fa18098a12cca0a1b4d818 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Wed, 27 Jul 2022 19:33:30 +0800 Subject: [PATCH] FIX: enable focus navigation in SpinInput/TextInput Change-Id: I32671cb8aa23f85b868284c41a66c583161e1b89 --- src/slic3r/GUI/Widgets/SpinInput.cpp | 47 ++++++++++++++++++---------- src/slic3r/GUI/Widgets/SpinInput.hpp | 14 ++++++++- src/slic3r/GUI/Widgets/TextInput.cpp | 4 ++- src/slic3r/GUI/Widgets/TextInput.hpp | 2 +- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/slic3r/GUI/Widgets/SpinInput.cpp b/src/slic3r/GUI/Widgets/SpinInput.cpp index 5cb556bbd..4d96d849e 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.cpp +++ b/src/slic3r/GUI/Widgets/SpinInput.cpp @@ -24,32 +24,46 @@ END_EVENT_TABLE() * calling Refresh()/Update(). */ -SpinInput::SpinInput(wxWindow * parent, +SpinInput::SpinInput() + : state_handler(this) + , border_color(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), + std::make_pair(0x00AE42, (int) StateColor::Focused), + std::make_pair(0x00AE42, (int) StateColor::Hovered), + std::make_pair(0xDBDBDB, (int) StateColor::Normal)) + , text_color(std::make_pair(0xACACAC, (int) StateColor::Disabled), std::make_pair(*wxBLACK, (int) StateColor::Normal)) + , background_color(std::make_pair(0xF0F0F0, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal)) +{ + hover = false; + radius = 0; +} + + +SpinInput::SpinInput(wxWindow *parent, wxString text, wxString label, const wxPoint &pos, const wxSize & size, long style, int min, int max, int initial) - : wxWindow(parent, wxID_ANY, pos, size) - , state_handler(this) - , border_color(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), - std::make_pair(0x00AE42, (int) StateColor::Focused), - std::make_pair(0x00AE42, (int) StateColor::Hovered), - std::make_pair(0xDBDBDB, (int) StateColor::Normal)) - , text_color(std::make_pair(0xACACAC, (int) StateColor::Disabled), - std::make_pair(*wxBLACK, (int) StateColor::Normal)) - , background_color(std::make_pair(0xF0F0F0, (int) StateColor::Disabled), - std::make_pair(*wxWHITE, (int) StateColor::Normal)) + : SpinInput() { - hover = false; - radius = 0; + Create(parent, text, label, pos, size, style, min, max, initial); +} + +void SpinInput::Create(wxWindow *parent, + wxString text, + wxString label, + const wxPoint &pos, + const wxSize & size, + long style, + int min, int max, int initial) +{ + wxWindow::Create(parent, wxID_ANY, pos, size); SetFont(Label::Body_12); 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, 4}, wxDefaultSize, - style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_DIGITS)); + 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) { @@ -74,8 +88,7 @@ SpinInput::SpinInput(wxWindow * parent, timer.Bind(wxEVT_TIMER, &SpinInput::onTimer, this); long initialFromText; - if ( text.ToLong(&initialFromText) ) - initial = initialFromText; + if (text.ToLong(&initialFromText)) initial = initialFromText; SetRange(min, max); SetValue(initial); messureSize(); diff --git a/src/slic3r/GUI/Widgets/SpinInput.hpp b/src/slic3r/GUI/Widgets/SpinInput.hpp index 2986a8eaa..aded55bfb 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.hpp +++ b/src/slic3r/GUI/Widgets/SpinInput.hpp @@ -7,7 +7,7 @@ class Button; -class SpinInput : public wxWindow +class SpinInput : public wxNavigationEnabled { bool hover; @@ -31,6 +31,8 @@ class SpinInput : public wxWindow static const int SpinInputHeight = 50; public: + SpinInput(); + SpinInput(wxWindow * parent, wxString text, wxString label = "", @@ -39,6 +41,16 @@ public: long style = 0, int min = 0, int max = 100, int initial = 0); + void Create(wxWindow * parent, + wxString text, + wxString label = "", + const wxPoint &pos = wxDefaultPosition, + const wxSize & size = wxDefaultSize, + long style = 0, + int min = 0, + int max = 100, + int initial = 0); + void SetCornerRadius(double radius); void SetLabel(const wxString &label) wxOVERRIDE; diff --git a/src/slic3r/GUI/Widgets/TextInput.cpp b/src/slic3r/GUI/Widgets/TextInput.cpp index a54fe984d..1b962a278 100644 --- a/src/slic3r/GUI/Widgets/TextInput.cpp +++ b/src/slic3r/GUI/Widgets/TextInput.cpp @@ -61,7 +61,6 @@ 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}); @@ -246,6 +245,9 @@ 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 + 8; if (size.y < h) { size.y = h; diff --git a/src/slic3r/GUI/Widgets/TextInput.hpp b/src/slic3r/GUI/Widgets/TextInput.hpp index e38de481d..92f5e8827 100644 --- a/src/slic3r/GUI/Widgets/TextInput.hpp +++ b/src/slic3r/GUI/Widgets/TextInput.hpp @@ -5,7 +5,7 @@ #include "../wxExtensions.hpp" #include "StateHandler.hpp" -class TextInput : public wxWindow +class TextInput : public wxNavigationEnabled { bool hover;