Implemented updating of the settings values for PointCtrl and Choice.
* wx_EVT_KILL_FOCES doesn't handled on OSX, so values are updating on wx_EVT_TEXT like a temporary workaround.
This commit is contained in:
parent
66b5deccf5
commit
7d1fb201e7
4 changed files with 52 additions and 13 deletions
|
@ -193,9 +193,10 @@ void Field::get_value_by_opt_type(wxString& str)
|
|||
}
|
||||
}
|
||||
|
||||
bool TextCtrl::is_defined_input_value() const
|
||||
template<class T>
|
||||
bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type)
|
||||
{
|
||||
if (static_cast<wxTextCtrl*>(window)->GetValue().empty() && m_opt.type != coString && m_opt.type != coStrings)
|
||||
if (static_cast<T*>(win)->GetValue().empty() && type != coString && type != coStrings)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -274,7 +275,7 @@ void TextCtrl::BUILD() {
|
|||
temp->GetToolTip()->Enable(true);
|
||||
#endif // __WXGTK__
|
||||
// if (!is_defined_input_value())
|
||||
if (is_defined_input_value())
|
||||
if (is_defined_input_value<wxTextCtrl>(window, m_opt.type))
|
||||
on_change_field();
|
||||
else
|
||||
on_kill_focus(e);
|
||||
|
@ -399,6 +400,9 @@ void SpinCtrl::BUILD() {
|
|||
0, min_val, max_val, default_value);
|
||||
|
||||
// temp->Bind(wxEVT_SPINCTRL, ([this](wxCommandEvent e) { tmp_value = undef_spin_val; on_change_field(); }), temp->GetId());
|
||||
|
||||
// #ys_FIXME_KILL_FOCUS
|
||||
// wxEVT_KILL_FOCUS doesn't handled on OSX now
|
||||
temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e)
|
||||
{
|
||||
if (tmp_value < 0)
|
||||
|
@ -408,6 +412,7 @@ void SpinCtrl::BUILD() {
|
|||
on_change_field();
|
||||
}
|
||||
}), temp->GetId());
|
||||
|
||||
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e)
|
||||
{
|
||||
// # On OSX / Cocoa, wxSpinCtrl::GetValue() doesn't return the new value
|
||||
|
@ -420,9 +425,15 @@ void SpinCtrl::BUILD() {
|
|||
tmp_value = std::stoi(value);
|
||||
else tmp_value = -9999;
|
||||
// on_change_field();
|
||||
// # We don't reset tmp_value here because _on_change might put callbacks
|
||||
// # in the CallAfter queue, and we want the tmp value to be available from
|
||||
// # them as well.
|
||||
#ifdef __WXOSX__
|
||||
// #ys_FIXME_KILL_FOCUS so call on_change_field() inside wxEVT_TEXT
|
||||
if (tmp_value < 0) {
|
||||
if (m_on_kill_focus != nullptr)
|
||||
m_on_kill_focus(m_opt_id);
|
||||
}
|
||||
else
|
||||
on_change_field();
|
||||
#endif
|
||||
}), temp->GetId());
|
||||
|
||||
temp->SetToolTip(get_tooltip_text(text_value));
|
||||
|
@ -454,9 +465,24 @@ void Choice::BUILD() {
|
|||
}
|
||||
set_selection();
|
||||
}
|
||||
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
|
||||
// temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
|
||||
temp->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
|
||||
|
||||
if (temp->GetWindowStyle() != wxCB_READONLY) {
|
||||
temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) {
|
||||
e.Skip();
|
||||
double old_val = !m_value.empty() ? boost::any_cast<double>(m_value) : -99999;
|
||||
if (is_defined_input_value<wxComboBox>(window, m_opt.type)) {
|
||||
if (fabs(old_val - boost::any_cast<double>(get_value())) <= 0.0001)
|
||||
return;
|
||||
else
|
||||
on_change_field();
|
||||
}
|
||||
else
|
||||
on_kill_focus(e);
|
||||
}), temp->GetId());
|
||||
}
|
||||
|
||||
temp->SetToolTip(get_tooltip_text(temp->GetValue()));
|
||||
}
|
||||
|
||||
|
@ -666,7 +692,7 @@ boost::any& Choice::get_value()
|
|||
if (ret_enum < 0 || m_opt.enum_values.empty())
|
||||
get_value_by_opt_type(ret_str);
|
||||
else
|
||||
m_value = m_opt.enum_values[ret_enum];
|
||||
m_value = atof(m_opt.enum_values[ret_enum].c_str());
|
||||
}
|
||||
else
|
||||
get_value_by_opt_type(ret_str);
|
||||
|
@ -733,8 +759,11 @@ void PointCtrl::BUILD()
|
|||
temp->Add(new wxStaticText(m_parent, wxID_ANY, " y : "), 0, wxALIGN_CENTER_VERTICAL, 0);
|
||||
temp->Add(y_textctrl);
|
||||
|
||||
x_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), x_textctrl->GetId());
|
||||
y_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), y_textctrl->GetId());
|
||||
// x_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), x_textctrl->GetId());
|
||||
// y_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), y_textctrl->GetId());
|
||||
|
||||
x_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { OnKillFocus(e, x_textctrl); }), x_textctrl->GetId());
|
||||
y_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { OnKillFocus(e, x_textctrl); }), y_textctrl->GetId());
|
||||
|
||||
// // recast as a wxWindow to fit the calling convention
|
||||
sizer = dynamic_cast<wxSizer*>(temp);
|
||||
|
@ -743,6 +772,16 @@ void PointCtrl::BUILD()
|
|||
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
|
||||
}
|
||||
|
||||
void PointCtrl::OnKillFocus(wxEvent& e, wxTextCtrl* win)
|
||||
{
|
||||
e.Skip();
|
||||
if (!win->GetValue().empty()) {
|
||||
on_change_field();
|
||||
}
|
||||
else
|
||||
on_kill_focus(e);
|
||||
}
|
||||
|
||||
void PointCtrl::set_value(const Vec2d& value, bool change_event)
|
||||
{
|
||||
m_disable_change_event = !change_event;
|
||||
|
|
|
@ -266,7 +266,6 @@ public:
|
|||
}
|
||||
|
||||
boost::any& get_value() override;
|
||||
bool is_defined_input_value() const ;
|
||||
|
||||
virtual void enable();
|
||||
virtual void disable();
|
||||
|
@ -395,6 +394,7 @@ public:
|
|||
|
||||
void BUILD() override;
|
||||
|
||||
void OnKillFocus(wxEvent& e, wxTextCtrl* win);
|
||||
void set_value(const Vec2d& value, bool change_event = false);
|
||||
void set_value(const boost::any& value, bool change_event = false);
|
||||
boost::any& get_value() override;
|
||||
|
|
|
@ -484,7 +484,7 @@ Sidebar::Sidebar(Plater *parent)
|
|||
: wxPanel(parent), p(new priv(parent))
|
||||
{
|
||||
p->scrolled = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(400, -1));
|
||||
p->scrolled->SetScrollbars(0, 1, 1, 1);
|
||||
p->scrolled->SetScrollbars(0, 20, 1, 2);
|
||||
|
||||
// Sizer in the scrolled area
|
||||
auto *scrolled_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
|
|
@ -270,7 +270,7 @@ Slic3r::GUI::PageShp Tab::add_options_page(const wxString& title, const std::str
|
|||
auto panel = this;
|
||||
#endif
|
||||
PageShp page(new Page(panel, title, icon_idx));
|
||||
page->SetScrollbars(1, 1, 1, 2);
|
||||
page->SetScrollbars(1, 20, 1, 2);
|
||||
page->Hide();
|
||||
m_hsizer->Add(page.get(), 1, wxEXPAND | wxLEFT, 5);
|
||||
|
||||
|
|
Loading…
Reference in a new issue