mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 07:03:59 -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().
|
* 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 text,
|
||||||
wxString label,
|
wxString label,
|
||||||
const wxPoint &pos,
|
const wxPoint &pos,
|
||||||
const wxSize & size,
|
const wxSize & size,
|
||||||
long style,
|
long style,
|
||||||
int min, int max, int initial)
|
int min, int max, int initial)
|
||||||
: wxWindow(parent, wxID_ANY, pos, size)
|
: 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;
|
Create(parent, text, label, pos, size, style, min, max, initial);
|
||||||
radius = 0;
|
}
|
||||||
|
|
||||||
|
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);
|
SetFont(Label::Body_12);
|
||||||
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, 4}, 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->SetInitialSize(text_ctrl->GetBestSize());
|
||||||
text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) {
|
text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) {
|
||||||
|
@ -74,8 +88,7 @@ SpinInput::SpinInput(wxWindow * parent,
|
||||||
timer.Bind(wxEVT_TIMER, &SpinInput::onTimer, this);
|
timer.Bind(wxEVT_TIMER, &SpinInput::onTimer, this);
|
||||||
|
|
||||||
long initialFromText;
|
long initialFromText;
|
||||||
if ( text.ToLong(&initialFromText) )
|
if (text.ToLong(&initialFromText)) initial = initialFromText;
|
||||||
initial = initialFromText;
|
|
||||||
SetRange(min, max);
|
SetRange(min, max);
|
||||||
SetValue(initial);
|
SetValue(initial);
|
||||||
messureSize();
|
messureSize();
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
class Button;
|
class Button;
|
||||||
|
|
||||||
class SpinInput : public wxWindow
|
class SpinInput : public wxNavigationEnabled<wxWindow>
|
||||||
{
|
{
|
||||||
|
|
||||||
bool hover;
|
bool hover;
|
||||||
|
@ -31,6 +31,8 @@ class SpinInput : public wxWindow
|
||||||
static const int SpinInputHeight = 50;
|
static const int SpinInputHeight = 50;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
SpinInput();
|
||||||
|
|
||||||
SpinInput(wxWindow * parent,
|
SpinInput(wxWindow * parent,
|
||||||
wxString text,
|
wxString text,
|
||||||
wxString label = "",
|
wxString label = "",
|
||||||
|
@ -39,6 +41,16 @@ public:
|
||||||
long style = 0,
|
long style = 0,
|
||||||
int min = 0, int max = 100, int initial = 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 SetCornerRadius(double radius);
|
||||||
|
|
||||||
void SetLabel(const wxString &label) wxOVERRIDE;
|
void SetLabel(const wxString &label) wxOVERRIDE;
|
||||||
|
|
|
@ -61,7 +61,6 @@ 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});
|
||||||
|
@ -246,6 +245,9 @@ 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__
|
||||||
|
textSize.y -= 3; // TODO:
|
||||||
|
#endif
|
||||||
int h = textSize.y + 8;
|
int h = textSize.y + 8;
|
||||||
if (size.y < h) {
|
if (size.y < h) {
|
||||||
size.y = h;
|
size.y = h;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "../wxExtensions.hpp"
|
#include "../wxExtensions.hpp"
|
||||||
#include "StateHandler.hpp"
|
#include "StateHandler.hpp"
|
||||||
|
|
||||||
class TextInput : public wxWindow
|
class TextInput : public wxNavigationEnabled<wxWindow>
|
||||||
{
|
{
|
||||||
|
|
||||||
bool hover;
|
bool hover;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue