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
This commit is contained in:
parent
b67ba50f14
commit
5544404f7a
2
CHANGES
2
CHANGES
@ -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.
|
||||
|
@ -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,16 +110,22 @@ 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.
|
||||
|
||||
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 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).
|
||||
|
||||
If wrap mode is off, the spinner value stops at the upper and lower bounds.
|
||||
\see minimum(), maximum()
|
||||
|
||||
\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.
|
||||
|
||||
\param[in] set non-zero sets wrap mode, zero resets wrap mode
|
||||
|
||||
\since 1.4.0
|
||||
|
@ -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$".
|
||||
//
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user