From d92bbf59e18f0e98809b805c6e1c43c406ad5dcd Mon Sep 17 00:00:00 2001 From: Pandagrapher Date: Mon, 1 Mar 2021 21:04:08 +0100 Subject: [PATCH] Fixes #6148, allow using decimal key on numpad --- rtgui/guiutils.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index 601fa422c..b1ebf05e6 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -1172,6 +1172,7 @@ MySpinButton::MySpinButton () set_numeric(true); set_wrap(false); set_alignment(Gtk::ALIGN_END); + set_update_policy(Gtk::SpinButtonUpdatePolicy::UPDATE_IF_VALID); // Avoid updating text if input is not a numeric } void MySpinButton::updateSize() @@ -1204,19 +1205,16 @@ bool MySpinButton::on_key_press_event (GdkEventKey* event) double vMin, vMax; get_range(vMin, vMax); - if ( (event->string[0] >= 'a' && event->string[0] <= 'z') - || (event->string[0] >= 'A' && event->string[0] <= 'Z') - || event->string[0] == '+' || (event->string[0] == '-' && vMin >= 0) - || event->string[0] == '=' || event->string[0] == '_' - ) { - return false; + if (event->keyval == GDK_KEY_plus || (event->keyval == GDK_KEY_minus && vMin >= 0)) { + return true; // Event is not propagated further } else { - if(event->string[0] == ',') { - event->keyval = GDK_KEY_period; - event->string[0] = '.'; + if (event->keyval == GDK_KEY_comma || event->keyval == GDK_KEY_KP_Decimal) { + set_text(get_text() + "."); + set_position(get_text().length()); // When setting text, cursor position is reseted at text start. Avoiding this with this code + return true; // Event is not propagated further } - return Gtk::Widget::on_key_press_event(event); + return Gtk::SpinButton::on_key_press_event(event); // Event is propagated normally } }