New method Fl_Spinner::wrap(int) to set wrap mode at bounds (STR #3365).

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12190 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2017-03-10 18:49:44 +00:00
parent 7123b78f3f
commit b67ba50f14
3 changed files with 43 additions and 9 deletions

View File

@ -46,6 +46,8 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017
- (add new items here) - (add new items here)
- Separated Fl_Spinner.H and Fl_Spinner.cxx (STR #2776). - 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).
- Renamed test/help.cxx demo program to test/help_dialog.cxx to avoid - Renamed test/help.cxx demo program to test/help_dialog.cxx to avoid
name conflict with CMake auto-generated target 'help'. name conflict with CMake auto-generated target 'help'.
- Many documentation fixes, clarifications, and enhancements. - Many documentation fixes, clarifications, and enhancements.

View File

@ -43,6 +43,7 @@ class FL_EXPORT Fl_Spinner : public Fl_Group {
double maximum_; // Maximum value double maximum_; // Maximum value
double step_; // Amount to add/subtract for up/down double step_; // Amount to add/subtract for up/down
const char *format_; // Format string for input field const char *format_; // Format string for input field
int wrap_; // wrap around at bounds (1/0)
private: private:
@ -96,6 +97,30 @@ public:
*/ */
double step() const { return (step_); } double step() const { return (step_); }
/** 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 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
*/
void wrap(int set) { wrap_ = set ? 1 : 0; }
/** Gets the wrap mode of the Fl_Spinner widget.
\see void wrap(int)
\since 1.4.0
*/
int wrap() const { return wrap_; }
/** Gets the color of the text in the input field. */ /** Gets the color of the text in the input field. */
Fl_Color textcolor() const { return (input_.textcolor()); } Fl_Color textcolor() const { return (input_.textcolor()); }

View File

@ -31,7 +31,7 @@
change the value. change the value.
*/ */
void Fl_Spinner::sb_cb(Fl_Widget *w, Fl_Spinner *sb) { void Fl_Spinner::sb_cb(Fl_Widget *w, Fl_Spinner *sb) {
double v; // New value double v; // New value
if (w == &(sb->input_)) { if (w == &(sb->input_)) {
@ -48,18 +48,24 @@ void Fl_Spinner::sb_cb(Fl_Widget *w, Fl_Spinner *sb) {
} else if (w == &(sb->up_button_)) { } else if (w == &(sb->up_button_)) {
// Up button pressed... // Up button pressed...
v = sb->value_ + sb->step_; v = sb->value_ + sb->step_;
if (v > sb->maximum_) {
if (v > sb->maximum_) sb->value_ = sb->minimum_; if (sb->wrap_)
else sb->value_ = v; v = sb->minimum_;
else
v = sb->maximum_;
}
sb->value_ = v;
sb->update(); sb->update();
} else if (w == &(sb->down_button_)) { } else if (w == &(sb->down_button_)) {
// Down button pressed... // Down button pressed...
v = sb->value_ - sb->step_; v = sb->value_ - sb->step_;
if (v < sb->minimum_) {
if (v < sb->minimum_) sb->value_ = sb->maximum_; if (sb->wrap_)
else sb->value_ = v; v = sb->maximum_;
else
v = sb->minimum_;
}
sb->value_ = v;
sb->update(); sb->update();
} }
@ -110,6 +116,7 @@ Fl_Spinner::Fl_Spinner(int X, int Y, int W, int H, const char *L)
minimum_ = 1.0; minimum_ = 1.0;
maximum_ = 100.0; maximum_ = 100.0;
step_ = 1.0; step_ = 1.0;
wrap_ = 1;
format_ = "%g"; format_ = "%g";
align(FL_ALIGN_LEFT); align(FL_ALIGN_LEFT);