mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 15:13:58 -06:00
FIX: enable focus navigation in SpinInput/TextInput
Change-Id: I32671cb8aa23f85b868284c41a66c583161e1b89
This commit is contained in:
parent
a302a58c9e
commit
7a5bca3c30
4 changed files with 47 additions and 20 deletions
|
@ -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();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
class Button;
|
||||
|
||||
class SpinInput : public wxWindow
|
||||
class SpinInput : public wxNavigationEnabled<wxWindow>
|
||||
{
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "../wxExtensions.hpp"
|
||||
#include "StateHandler.hpp"
|
||||
|
||||
class TextInput : public wxWindow
|
||||
class TextInput : public wxNavigationEnabled<wxWindow>
|
||||
{
|
||||
|
||||
bool hover;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue