Adding event handling for on_change and on_kill_focus

This commit is contained in:
Joseph Lenox 2018-07-04 12:49:38 -05:00 committed by Joseph Lenox
parent e4fd688c78
commit c2c80ecd92
2 changed files with 18 additions and 2 deletions

View File

@ -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<std::string, std::string>(_ctrl_x->GetValue().ToStdString(), _ctrl_y->GetValue().ToStdString()));
}
}
};

View File

@ -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<ConfigOptionPoint*>(_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