FLTK
Fl_Spinner.H
1 //
2 // Spinner widget for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2017 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16 
17 /* \file
18  Fl_Spinner widget . */
19 
20 #ifndef Fl_Spinner_H
21 #define Fl_Spinner_H
22 
23 #include <FL/Enumerations.H>
24 #include <FL/Fl_Group.H>
25 #include <FL/Fl_Input.H>
26 #include <FL/Fl_Repeat_Button.H>
27 
37 class FL_EXPORT Fl_Spinner : public Fl_Group {
38 
39  double value_; // Current value
40  double minimum_; // Minimum value
41  double maximum_; // Maximum value
42  double step_; // Amount to add/subtract for up/down
43  const char *format_; // Format string for input field
44  int wrap_; // wrap around at bounds (1/0)
45 
46 private:
47 
48  static void sb_cb(Fl_Widget *w, Fl_Spinner *sb); // internal callback
49  void update(); // update input field
50 
51 protected:
52 
53  // This class works like Fl_Input but ignores FL_Up and FL_Down key
54  // presses so they are handled by its parent, the Fl_Spinner widget.
55  // See STR #2989.
56 
57  class FL_EXPORT Fl_Spinner_Input : public Fl_Input {
58  public:
59  Fl_Spinner_Input(int X, int Y, int W, int H)
60  : Fl_Input(X, Y, W, H) {}
61  int handle(int event); // implemented in src/Fl_Spinner.cxx
62  };
63 
64  Fl_Spinner_Input input_; // Input field for the value
66  up_button_, // Up button
67  down_button_; // Down button
68 
69 public:
70 
71  // Constructor
72  Fl_Spinner(int X, int Y, int W, int H, const char *L = 0);
73  // Event handling
74  int handle(int event);
75  // Resize group and subwidgets
76  void resize(int X, int Y, int W, int H);
77 
79  const char *format() const { return (format_); }
80 
82  void format(const char *f) { format_ = f; update(); }
83 
85  double maximum() const { return (maximum_); }
86 
88  void maximum(double m) { maximum_ = m; }
89 
91  double minimum() const { return (minimum_); }
92 
94  void minimum(double m) { minimum_ = m; }
95 
97  void range(double a, double b) { minimum_ = a; maximum_ = b; }
98 
99  // Sets the amount to change the value when the user clicks a button.
100  // Docs in src/Fl_Spinner.cxx
101  void step(double s);
102 
107  double step() const { return (step_); }
108 
131  void wrap(int set) { wrap_ = set ? 1 : 0; }
132 
137  int wrap() const { return wrap_; }
138 
140  Fl_Color textcolor() const { return (input_.textcolor()); }
141 
143  void textcolor(Fl_Color c) { input_.textcolor(c); }
144 
146  Fl_Font textfont() const { return (input_.textfont()); }
147 
149  void textfont(Fl_Font f) { input_.textfont(f); }
150 
152  Fl_Fontsize textsize() const { return (input_.textsize()); }
153 
155  void textsize(Fl_Fontsize s) { input_.textsize(s); }
156 
157  // Sets the numeric representation in the input field.
158  // Docs see src/Fl_Spinner.cxx
159  void type(uchar v);
160 
164  uchar type() const { return (input_.type()); }
165 
167  double value() const { return (value_); }
168 
174  void value(double v) { value_ = v; update(); }
175 
179  void color(Fl_Color v) { input_.color(v); }
180 
184  Fl_Color color() const { return(input_.color()); }
185 
189  void selection_color(Fl_Color val) { input_.selection_color(val); }
190 
194  Fl_Color selection_color() const { return input_.selection_color(); }
195 
199  void maximum_size(int m) { if (m > 0) input_.maximum_size(m); }
200 
204  int maximum_size() const { return input_.maximum_size(); }
205 };
206 
207 #endif // !Fl_Spinner_H
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
int maximum_size() const
Gets the maximum length of the input field in characters.
Definition: Fl_Input_.H:265
void maximum_size(int m)
Sets the maximum width of the input field.
Definition: Fl_Spinner.H:199
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition: Fl_Input_.H:397
double step() const
Gets the amount to change the value when the user clicks a button.
Definition: Fl_Spinner.H:107
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition: Fl_Spinner.H:146
void textsize(Fl_Fontsize s)
Sets the size of the text in the input field.
Definition: Fl_Spinner.H:155
Fl_Input(int, int, int, int, const char *=0)
Creates a new Fl_Input widget using the given position, size, and label string.
Definition: Fl_Input.cxx:661
void wrap(int set)
Sets whether the spinner wraps around at upper and lower bounds.
Definition: Fl_Spinner.H:131
Fl_Color selection_color() const
Returns the selection color of the spinner widget&#39;s input field.
Definition: Fl_Spinner.H:194
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition: Fl_Spinner.H:140
void selection_color(Fl_Color val)
Sets the selection color of the spinner widget&#39;s input field.
Definition: Fl_Spinner.H:189
uchar type() const
Gets the widget type.
Definition: Fl_Widget.H:261
int wrap() const
Gets the wrap mode of the Fl_Spinner widget.
Definition: Fl_Spinner.H:137
uchar type() const
Gets the numeric representation in the input field.
Definition: Fl_Spinner.H:164
This is the FLTK text input widget.
Definition: Fl_Input.H:220
Fl_Color color() const
Returns the background color of the spinner widget&#39;s input field.
Definition: Fl_Spinner.H:184
void value(double v)
Sets the current value of the input widget.
Definition: Fl_Spinner.H:174
double value() const
Gets the current value of the widget.
Definition: Fl_Spinner.H:167
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:42
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition: Fl_Input_.H:388
This file contains type definitions and general enumerations.
void textfont(Fl_Font f)
Sets the font of the text in the input field.
Definition: Fl_Spinner.H:149
void minimum(double m)
Sets the minimum value of the widget.
Definition: Fl_Spinner.H:94
void resize(int, int, int, int)
Changes the size of the widget.
Definition: Fl_Input_.cxx:1306
The Fl_Repeat_Button is a subclass of Fl_Button that generates a callback when it is pressed and then...
Definition: Fl_Repeat_Button.H:31
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
This widget is a combination of a numerical input widget and repeat buttons.
Definition: Fl_Spinner.H:37
double maximum() const
Gets the maximum value of the widget.
Definition: Fl_Spinner.H:85
void maximum(double m)
Sets the maximum value of the widget.
Definition: Fl_Spinner.H:88
int maximum_size() const
Returns the maximum width of the input field.
Definition: Fl_Spinner.H:204
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:1042
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
void color(Fl_Color v)
Sets the background color of the spinner widget&#39;s input field.
Definition: Fl_Spinner.H:179
void format(const char *f)
Sets the format string for the value.
Definition: Fl_Spinner.H:82
Definition: Fl_Spinner.H:57
Fl_Color color() const
Gets the background color of the widget.
Definition: Fl_Widget.H:365
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition: Fl_Input_.H:407
void range(double a, double b)
Sets the minimum and maximum values for the widget.
Definition: Fl_Spinner.H:97
double minimum() const
Gets the minimum value of the widget.
Definition: Fl_Spinner.H:91
const char * format() const
Returns the format string for the value.
Definition: Fl_Spinner.H:79
void textcolor(Fl_Color c)
Sets the color of the text in the input field.
Definition: Fl_Spinner.H:143
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition: Fl_Spinner.H:152
int handle(int)
Handles the specified event.
Definition: Fl_Input.cxx:457
unsigned char uchar
unsigned char
Definition: fl_types.h:28
Fl_Color selection_color() const
Gets the selection color.
Definition: Fl_Widget.H:383