From a302a58c9e731bf906dd5ff97a5cdcb9c006626a Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Thu, 28 Jul 2022 13:17:03 +0800 Subject: [PATCH] FIX: support key event in SpinInput Change-Id: Ie25404c8dec25b0b4012cae51a1f57c95d9fca66 --- src/slic3r/GUI/Widgets/SpinInput.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Widgets/SpinInput.cpp b/src/slic3r/GUI/Widgets/SpinInput.cpp index e68806040..5cb556bbd 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.cpp +++ b/src/slic3r/GUI/Widgets/SpinInput.cpp @@ -66,6 +66,7 @@ SpinInput::SpinInput(wxWindow * parent, }); text_ctrl->Bind(wxEVT_KILL_FOCUS, &SpinInput::onTextLostFocus, this); text_ctrl->Bind(wxEVT_TEXT_ENTER, &SpinInput::onTextEnter, this); + text_ctrl->Bind(wxEVT_KEY_DOWN, &SpinInput::keyPressed, this); text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu button_inc = createButton(true); button_dec = createButton(false); @@ -313,7 +314,27 @@ void SpinInput::mouseWheelMoved(wxMouseEvent &event) // currently unused events void SpinInput::mouseMoved(wxMouseEvent& event) {} -void SpinInput::keyPressed(wxKeyEvent& event) {} + +void SpinInput::keyPressed(wxKeyEvent &event) +{ + switch (event.GetKeyCode()) { + case WXK_UP: + case WXK_DOWN: + long value; + if (!text_ctrl->GetValue().ToLong(&value)) { value = val; } + if (event.GetKeyCode() == WXK_DOWN && value > min) { + --value; + } else if (event.GetKeyCode() == WXK_UP && value + 1 < max) { + ++value; + } + if (value != val) { + SetValue(value); + sendSpinEvent(); + } + break; + default: event.Skip(); break; + } +} void SpinInput::keyReleased(wxKeyEvent &event) {} void SpinInput::sendSpinEvent()