summaryrefslogtreecommitdiff
path: root/FL/Fl_Spinner.H
blob: bac216e70c84d31396609c3302c369522d7bf1fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// "$Id$"
//
// Spinner widget for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2017 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//
//     http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
//     http://www.fltk.org/str.php
//

/* \file
   Fl_Spinner widget . */

#ifndef Fl_Spinner_H
#define Fl_Spinner_H

#include <FL/Enumerations.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Repeat_Button.H>

/**
  This widget is a combination of a numerical input widget and repeat buttons.

  The user can either type into the input area or use the buttons to
  change the value.

  \image html Fl_Spinner.png "Fl_Spinner widget"
  \image latex Fl_Spinner.png "Fl_Spinner widget" width=6cm
*/
class FL_EXPORT Fl_Spinner : public Fl_Group {

  double	value_;			// Current value
  double	minimum_;		// Minimum value
  double	maximum_;		// Maximum value
  double	step_;			// Amount to add/subtract for up/down
  const char	*format_;		// Format string for input field
  int		wrap_;			// wrap around at bounds (1/0)

private:

  static void sb_cb(Fl_Widget *w, Fl_Spinner *sb); // internal callback
  void update();				   // update input field

protected:

  Fl_Input	input_;			// Input field for the value
  Fl_Repeat_Button
		up_button_,		// Up button
		down_button_;		// Down button

public:

  // Constructor
  Fl_Spinner(int X, int Y, int W, int H, const char *L = 0);
  // Event handling
  int handle(int event);
  // Resize group and subwidgets
  void resize(int X, int Y, int W, int H);

  /** Returns the format string for the value. */
  const char *format() const { return (format_); }

  /** Sets the format string for the value. */
  void format(const char *f) { format_ = f; update(); }

  /** Gets the maximum value of the widget. */
  double maximum() const { return (maximum_); }

  /** Sets the maximum value of the widget. */
  void maximum(double m) { maximum_ = m; }

  /** Gets the minimum value of the widget. */
  double minimum() const { return (minimum_); }

  /** Sets the minimum value of the widget. */
  void minimum(double m) { minimum_ = m; }

  /** Sets the minimum and maximum values for the widget. */
  void range(double a, double b) { minimum_ = a; maximum_ = b; }

  // Sets the amount to change the value when the user clicks a button.
  // Docs in src/Fl_Spinner.cxx
  void step(double s);

  /**
    Gets the amount to change the value when the user clicks a button.
    \see Fl_Spinner::step(double)
  */
  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. */
  Fl_Color textcolor() const { return (input_.textcolor()); }

  /** Sets the color of the text in the input field. */
  void textcolor(Fl_Color c) { input_.textcolor(c); }

  /** Gets the font of the text in the input field. */
  Fl_Font textfont() const { return (input_.textfont()); }

  /** Sets the font of the text in the input field. */
  void textfont(Fl_Font f) { input_.textfont(f); }

  /** Gets the size of the text in the input field. */
  Fl_Fontsize textsize() const { return (input_.textsize()); }

  /** Sets the size of the text in the input field. */
  void textsize(Fl_Fontsize s) { input_.textsize(s); }

  // Sets the numeric representation in the input field.
  // Docs see src/Fl_Spinner.cxx
  void type(uchar v);

  /** Gets the numeric representation in the input field.
    \see Fl_Spinner::type(uchar)
  */
  uchar type() const { return (input_.type()); }

  /** Gets the current value of the widget. */
  double value() const { return (value_); }

  /**
    Sets the current value of the input widget.
    Before setting value to a non-integer value, the spinner
    type() should be changed to floating point.
  */
  void value(double v) { value_ = v; update(); }

  /**
    Sets the background color of the spinner widget's input field.
  */
  void color(Fl_Color v) { input_.color(v); }

  /**
    Returns the background color of the spinner widget's input field.
  */
  Fl_Color color() const { return(input_.color()); }

  /**
    Sets the selection color of the spinner widget's input field.
  */
  void selection_color(Fl_Color val) { input_.selection_color(val); }

  /**
    Returns the selection color of the spinner widget's input field.
  */
  Fl_Color selection_color() const { return input_.selection_color(); }
};

#endif // !Fl_Spinner_H


//
// End of "$Id$".
//