diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2017-03-10 21:47:08 +0000 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2017-03-10 21:47:08 +0000 |
| commit | 5544404f7a89a3d7e781f5e57d1271076485c91c (patch) | |
| tree | f1d97d7bf5723b80da09ccdcaf67d1f3ff01b733 | |
| parent | b67ba50f147534bcf2beb3305dbcf24e20ff2e72 (diff) | |
Enable Up/Down keys in Fl_Spinner if input has focus (STR #2989).
Previously Up/Down keys worked only if one of the buttons was pressed
before so that it had the focus.
test/valuators.fl: The second Fl_Spinner widget (FL_FLOAT_INPUT) now has
wrap mode disabled whereas the first one (FL_INT_INPUT) uses wrap mode
(default, compatible with FLTK 1.3.x and older).
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12191 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | FL/Fl_Spinner.H | 33 | ||||
| -rw-r--r-- | src/Fl_Spinner.cxx | 18 | ||||
| -rw-r--r-- | test/valuators.fl | 1 |
4 files changed, 46 insertions, 8 deletions
@@ -48,6 +48,8 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017 - Separated Fl_Spinner.H and Fl_Spinner.cxx (STR #2776). - New method Fl_Spinner::wrap(int) allows to set wrap mode at bounds if value is changed by pressing or holding one of the buttons (STR #3365). + - Fl_Spinner now handles Up and Down keys when the input field has + keyboard focus (STR #2989). - Renamed test/help.cxx demo program to test/help_dialog.cxx to avoid name conflict with CMake auto-generated target 'help'. - Many documentation fixes, clarifications, and enhancements. diff --git a/FL/Fl_Spinner.H b/FL/Fl_Spinner.H index bac216e70..d5d530743 100644 --- a/FL/Fl_Spinner.H +++ b/FL/Fl_Spinner.H @@ -52,7 +52,18 @@ private: protected: - Fl_Input input_; // Input field for the value + // This class works like Fl_Input but ignores FL_Up and FL_Down key + // presses so they are handled by its parent, the Fl_Spinner widget. + // See STR #2989. + + class Fl_Spinner_Input : public Fl_Input { + public: + Fl_Spinner_Input(int X, int Y, int W, int H) + : Fl_Input(X, Y, W, H) {} + int handle(int event); // implemented in src/Fl_Spinner.cxx + }; + + Fl_Spinner_Input input_; // Input field for the value Fl_Repeat_Button up_button_, // Up button down_button_; // Down button @@ -99,15 +110,21 @@ public: /** Sets whether the spinner wraps around at upper and lower bounds. - If wrap mode is on (default) the spinner value is set to the minimum() - or maximum() when the value exceeds the upper or lower bounds, resp., - if the value was changed by one of the buttons. + If wrap mode is on the spinner value is set to the minimum() or + maximum() if the value exceeds the upper or lower bounds, resp., if + it was changed by one of the buttons or the FL_Up or FL_Down keys. - If wrap mode is off, the spinner value stops at the upper and lower bounds. - \see minimum(), maximum() + The spinner stops at the upper and lower bounds if wrap mode is off. + + The default wrap mode is on for backwards compatibility with + FLTK 1.3.x and older versions. - \note This does not apply to the input field. The input value is always - clipped to the allowed range as if wrap mode was off. + \note Wrap mode does not apply to the input field if the input value + is edited directly as a number. The input value is always + clipped to the allowed range as if wrap mode was off when the + input field is left (i.e. loses focus). + + \see minimum(), maximum() \param[in] set non-zero sets wrap mode, zero resets wrap mode diff --git a/src/Fl_Spinner.cxx b/src/Fl_Spinner.cxx index 220ac1698..3ef102a55 100644 --- a/src/Fl_Spinner.cxx +++ b/src/Fl_Spinner.cxx @@ -196,6 +196,24 @@ void Fl_Spinner::type(uchar v) { } +/** + Handles events of Fl_Spinner's embedded input widget. + + Works like Fl_Input::handle() but ignores FL_Up and FL_Down keys + so they can be handled by the parent widget (Fl_Spinner). +*/ +int Fl_Spinner::Fl_Spinner_Input::handle(int event) { + if (event == FL_KEYBOARD) { + const int key = Fl::event_key(); + if (key == FL_Up || key == FL_Down) { + Fl_Input::handle(FL_UNFOCUS); // sets and potentially clips the input value + return 0; + } + } + return Fl_Input::handle(event); +} + + // // End of "$Id$". // diff --git a/test/valuators.fl b/test/valuators.fl index 5df70e55c..4d740808c 100644 --- a/test/valuators.fl +++ b/test/valuators.fl @@ -154,6 +154,7 @@ Function {} {open Fl_Spinner {} { label FL_FLOAT_INPUT xywh {465 216 80 24} type Float labelsize 8 align 2 minimum 0 maximum 1 step 0.01 value 0.05 + code0 {o->wrap(0); // disable wrap mode} } Fl_Box {} { label Fl_Dial |
