ENH: restrict the scope of multiplier

JIRA: STUDIO-5781
1. restrict the scope of multiplier
2. Only numerical values can be entered in the input box

Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com>
Change-Id: Ie3cff3731b0e42c4bf8dbc879f3e4a74e0724224
This commit is contained in:
Kunlong Ma 2024-01-08 15:46:23 +08:00 committed by Lane.Wei
parent 8cba6a3566
commit 35836654ef
1 changed files with 34 additions and 0 deletions

View File

@ -460,8 +460,42 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, con
param_sizer->AddStretchSpacer(1);
m_sizer_advanced->Add(param_sizer, 0, wxEXPAND | wxLEFT, TEXT_BEG_PADDING);
wxStaticText* suggest = new wxStaticText(m_page_advanced, wxID_ANY, wxString::Format(_L("The multiplier should be in range [%.2f, %.2f]."), g_min_flush_multiplier, g_max_flush_multiplier));
suggest->SetForegroundColour(g_text_color);
m_sizer_advanced->Add(suggest, 0, wxEXPAND | wxLEFT, TEXT_BEG_PADDING);
m_sizer_advanced->AddSpacer(5);
m_flush_multiplier_ebox->Bind(wxEVT_TEXT_ENTER, on_apply_text_modify);
m_flush_multiplier_ebox->Bind(wxEVT_KILL_FOCUS, on_apply_text_modify);
m_flush_multiplier_ebox->Bind(wxEVT_COMMAND_TEXT_UPDATED, [this](wxCommandEvent&) {
wxString str = m_flush_multiplier_ebox->GetValue();
float multiplier = wxAtof(str);
if (multiplier < g_min_flush_multiplier || multiplier > g_max_flush_multiplier) {
str = wxString::Format(("%.2f"), multiplier < g_min_flush_multiplier ? g_min_flush_multiplier : g_max_flush_multiplier);
m_flush_multiplier_ebox->SetValue(str);
m_flush_multiplier_ebox->SetInsertionPointEnd();
}
});
m_flush_multiplier_ebox->Bind(wxEVT_CHAR, [this](wxKeyEvent& e) {
int keycode = e.GetKeyCode();
if (keycode == WXK_NONE)
return;
if (keycode == WXK_BACK || keycode == WXK_DELETE || keycode == WXK_RETURN ||
keycode == WXK_LEFT || keycode == WXK_RIGHT ||
keycode == WXK_HOME || keycode == WXK_END) {
e.Skip();
return;
}
wxString input_char = wxString::Format("%c", keycode);
long value;
if (!input_char.ToLong(&value) && input_char != ".")
return;
e.Skip();
});
}
this->update_warning_texts();