From 131d2ace50ae313fb67d1f5d5ede988c7d776cf8 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 12 Aug 2021 10:15:46 +0200 Subject: [PATCH] =?UTF-8?q?Check=20min/max=20values=20for=20SpinCtrls?= =?UTF-8?q?=C2=A0in=20Settings=20Tabs=20+=20Set=20max=20value=20for=20"ext?= =?UTF-8?q?ruders=5Fcount"=20to=20256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/slic3r/GUI/Field.cpp | 30 +++++++++++++++++++----------- src/slic3r/GUI/Tab.cpp | 1 + 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 69072d375..1aaac5469 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -823,7 +823,7 @@ void SpinCtrl::BUILD() { bEnterPressed = true; }), temp->GetId()); - temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) + temp->Bind(wxEVT_TEXT, ([this, temp](wxCommandEvent e) { // # On OSX / Cocoa, wxSpinCtrl::GetValue() doesn't return the new value // # when it was changed from the text control, so the on_change callback @@ -833,20 +833,28 @@ void SpinCtrl::BUILD() { long value; const bool parsed = e.GetString().ToLong(&value); - tmp_value = parsed && value >= INT_MIN && value <= INT_MAX ? (int)value : UNDEF_VALUE; - + if (!parsed || value < INT_MIN || value > INT_MAX) + tmp_value = UNDEF_VALUE; + else { + tmp_value = std::min(std::max((int)value, m_opt.min), m_opt.max); #ifdef __WXOSX__ - // Forcibly set the input value for SpinControl, since the value - // inserted from the keyboard or clipboard is not updated under OSX - if (tmp_value != UNDEF_VALUE) { - wxSpinCtrl* spin = static_cast(window); - spin->SetValue(tmp_value); - + // Forcibly set the input value for SpinControl, since the value + // inserted from the keyboard or clipboard is not updated under OSX + temp->SetValue(tmp_value); // But in SetValue() is executed m_text_ctrl->SelectAll(), so // discard this selection and set insertion point to the end of string - spin->GetText()->SetInsertionPointEnd(); - } + temp->GetText()->SetInsertionPointEnd(); +#else + // update value for the control only if it was changed in respect to the Min/max values + if (tmp_value != (int)value) { + temp->SetValue(tmp_value); + // But after SetValue() cursor ison the first position + // so put it to the end of string + int pos = std::to_string(tmp_value).length(); + temp->SetSelection(pos, pos); + } #endif + } }), temp->GetId()); temp->SetToolTip(get_tooltip_text(text_value)); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 0d1ce1092..5c8fed787 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2208,6 +2208,7 @@ void TabPrinter::build_fff() def.label = L("Extruders"); def.tooltip = L("Number of extruders of the printer."); def.min = 1; + def.max = 256; def.mode = comExpert; Option option(def, "extruders_count"); optgroup->append_single_option_line(option);