mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-04 02:50:38 +08:00
Adding event handling for on_change and on_kill_focus
This commit is contained in:
parent
e4fd688c78
commit
c2c80ecd92
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user