Added template for the handle of the TextCtrl's focus event

This commit is contained in:
YuSanka 2018-12-11 13:57:50 +01:00
parent d7bc1410ee
commit e1cea03cda
6 changed files with 36 additions and 0 deletions

View File

@ -77,6 +77,15 @@ void Field::on_kill_focus(wxEvent& event)
m_on_kill_focus(m_opt_id);
}
void Field::on_set_focus(wxEvent& event)
{
// to allow the default behavior
event.Skip();
// call the registered function if it is available
if (m_on_set_focus!=nullptr)
m_on_set_focus(m_opt_id);
}
void Field::on_change_field()
{
// std::cerr << "calling Field::_on_change \n";
@ -220,6 +229,8 @@ void TextCtrl::BUILD() {
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, style);
temp->SetToolTip(get_tooltip_text(text_value));
temp->Bind(wxEVT_SET_FOCUS, ([this](wxEvent& e) { on_set_focus(e); }), temp->GetId());
temp->Bind(wxEVT_LEFT_DOWN, ([temp](wxEvent& event)
{

View File

@ -76,6 +76,8 @@ protected:
//! in another case we can't unfocused control at all
void on_kill_focus(wxEvent& event);
/// Call the attached on_change method.
void on_set_focus(wxEvent& event);
/// Call the attached on_change method.
void on_change_field();
/// Call the attached m_back_to_initial_value method.
void on_back_to_initial_value();
@ -89,6 +91,9 @@ public:
/// Function object to store callback passed in from owning object.
t_kill_focus m_on_kill_focus {nullptr};
/// Function object to store callback passed in from owning object.
t_kill_focus m_on_set_focus {nullptr};
/// Function object to store callback passed in from owning object.
t_change m_on_change {nullptr};

View File

@ -971,6 +971,8 @@ public:
void viewport_changed();
#endif // ENABLE_CONSTRAINED_CAMERA_TARGET
void handle_sidebar_focus_event(const std::string& opt_key) {}
private:
bool _is_shown_on_screen() const;
void _force_zoom_to_bed();

View File

@ -71,6 +71,11 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
m_og->set_value(opt_key, double_to_string(0.0));
};
m_og->m_set_focus = [this](const std::string& opt_key)
{
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key);
};
ConfigOptionDef def;
// Objects(sub-objects) name

View File

@ -78,6 +78,11 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co
if (!m_disabled)
this->on_kill_focus(opt_id);
};
field->m_on_set_focus = [this](const std::string& opt_id) {
//! This function will be called from Field.
if (!m_disabled)
this->on_set_focus(opt_id);
};
field->m_parent = parent();
//! Label to change background color, when option is modified
@ -277,6 +282,12 @@ Line OptionsGroup::create_single_option_line(const Option& option) const {
return retval;
}
void OptionsGroup::on_set_focus(const std::string& opt_key)
{
if (m_set_focus != nullptr)
m_set_focus(opt_key);
}
void OptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value) {
if (m_on_change != nullptr)
m_on_change(opt_id, value);

View File

@ -87,6 +87,7 @@ public:
column_t extra_column {nullptr};
t_change m_on_change { nullptr };
t_kill_focus m_fill_empty_value { nullptr };
t_kill_focus m_set_focus { nullptr };
std::function<DynamicPrintConfig()> m_get_initial_config{ nullptr };
std::function<DynamicPrintConfig()> m_get_sys_config{ nullptr };
std::function<bool()> have_sys_config{ nullptr };
@ -210,6 +211,7 @@ protected:
void add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field);
virtual void on_kill_focus(const std::string& opt_key) {};
virtual void on_set_focus(const std::string& opt_key);
virtual void on_change_OG(const t_config_option_key& opt_id, const boost::any& value);
virtual void back_to_initial_value(const std::string& opt_key) {}
virtual void back_to_sys_value(const std::string& opt_key) {}