From c2c80ecd92e98c2add7264e0b0c6b739b445295c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 4 Jul 2018 12:49:38 -0500 Subject: [PATCH] Adding event handling for on_change and on_kill_focus --- src/GUI/OptionsGroup/Field.hpp | 9 +++++++++ src/GUI/OptionsGroup/UI_Point.cpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/GUI/OptionsGroup/Field.hpp b/src/GUI/OptionsGroup/Field.hpp index ae99d4385..c7b32873f 100644 --- a/src/GUI/OptionsGroup/Field.hpp +++ b/src/GUI/OptionsGroup/Field.hpp @@ -294,6 +294,8 @@ public: void disable() { _ctrl_x->Disable(); _ctrl_y->Disable(); } void toggle(bool en = true) { en ? this->enable() : this->disable(); } + bool disable_change_event {false}; + protected: virtual std::string LogChannel() { return "UI_Point"s; } @@ -302,6 +304,8 @@ private: wxStaticText* _lbl_x {nullptr}; wxStaticText* _lbl_y {nullptr}; + wxWindow* window {nullptr}; + wxTextCtrl* _ctrl_x {nullptr}; wxTextCtrl* _ctrl_y {nullptr}; @@ -320,6 +324,11 @@ private: } wxString trim_zeroes(wxString in) { return wxString(trim_zeroes(in.ToStdString())); } + void _on_change(std::string opt_id) { + if (!this->disable_change_event && this->window->IsEnabled() && this->on_change != nullptr) { + this->on_change(opt_id, std::make_pair(_ctrl_x->GetValue().ToStdString(), _ctrl_y->GetValue().ToStdString())); + } + } }; diff --git a/src/GUI/OptionsGroup/UI_Point.cpp b/src/GUI/OptionsGroup/UI_Point.cpp index 2dfdedf35..31caa679a 100644 --- a/src/GUI/OptionsGroup/UI_Point.cpp +++ b/src/GUI/OptionsGroup/UI_Point.cpp @@ -59,11 +59,18 @@ void UI_Point::_set_value(std::string value) { UI_Point::UI_Point(wxWindow* parent, Slic3r::ConfigOptionDef _opt, wxWindowID id) { Slic3r::Pointf def_val {_opt.default_value == nullptr ? Pointf() : Pointf(*(dynamic_cast(_opt.default_value))) }; - this->_ctrl_x = new wxTextCtrl(parent, wxID_ANY, trim_zeroes(wxString::FromDouble(def_val.x)), wxDefaultPosition, this->field_size); - this->_ctrl_y = new wxTextCtrl(parent, wxID_ANY, trim_zeroes(wxString::FromDouble(def_val.y)), wxDefaultPosition, this->field_size); + this->_ctrl_x = new wxTextCtrl(parent, wxID_ANY, trim_zeroes(wxString::FromDouble(def_val.x)), wxDefaultPosition, this->field_size, wxTE_PROCESS_ENTER); + this->_ctrl_y = new wxTextCtrl(parent, wxID_ANY, trim_zeroes(wxString::FromDouble(def_val.y)), wxDefaultPosition, this->field_size, wxTE_PROCESS_ENTER); + + this->window = this->_ctrl_x; this->_lbl_x = new wxStaticText(parent, wxID_ANY, wxString("x:")); this->_lbl_y = new wxStaticText(parent, wxID_ANY, wxString("y:")); + + _ctrl_x->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent& e) { this->_on_change(""); e.Skip(); }); + _ctrl_y->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent& e) { this->_on_change(""); e.Skip(); }); + _ctrl_x->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e) { if (this->on_kill_focus != nullptr) {this->on_kill_focus(""); this->_on_change("");} e.Skip(); }); + _ctrl_y->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e) { if (this->on_kill_focus != nullptr) {this->on_kill_focus(""); this->_on_change("");} e.Skip(); }); } } } // Namespace Slic3r::GUI