1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 retrieve an integer or floating-point number from the user.
7 <!-- ##### SECTION Long_Description ##### -->
9 A #GtkSpinButton is an ideal way to allow the user to set the value of some attribute. Rather than having to directly type a number into a #GtkEntry, #GtkSpinButton allows the user to click on one of two arrows to increment or decrement the displayed value. A value can still be typed in, with the bonus that it can be checked to ensure it is in a given range.
12 The main properties of a #GtkSpinButton are through a #GtkAdjustment. See the #GtkAdjustment section for more details about an adjustment's properties.
16 <title>Using a GtkSpinButton to get an integer.</title>
19 /* Provides a function to retrieve an integer value from a GtkSpinButton
20 * and creates a spin button to model percentage values.
23 gint grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
24 return gtk_spin_button_get_value_as_int (a_spinner);
27 void create_integer_spin_button(void) {
29 GtkWidget *window, *spinner;
30 GtkAdjustment *spinner_adj;
32 spinner_adj = (GtkAdjustment *) gtk_adjustment_new(50.0, 0.0, 100.0, 1.0, 5.0, 5.0);
34 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
35 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
37 /* creates the spinner, with no decimal places */
38 spinner = gtk_spin_button_new (spinner_adj, 1.0, 0);
39 gtk_container_add (GTK_CONTAINER(window), spinner);
41 gtk_widget_show_all (window);
51 <title>Using a GtkSpinButton to get a floating point value.</title>
54 /* Provides a function to retrieve a floating point value from a
55 * GtkSpinButton, and creates a high precision spin button.
58 gfloat grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
59 return gtk_spin_button_get_value_as_float (a_spinner);
62 void create_floating_spin_button(void) {
64 GtkWidget *window, *spinner;
65 GtkAdjustment *spinner_adj;
67 spinner_adj = (GtkAdjustment *) gtk_adjustment_new(2.500, 0.0, 5.0, 0.001, 0.1, 0.1);
69 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
70 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
72 /* creates the spinner, with three decimal places */
73 spinner = gtk_spin_button_new (spinner_adj, 0.001, 3);
74 gtk_container_add (GTK_CONTAINER(window), spinner);
76 gtk_widget_show_all (window);
84 <!-- ##### SECTION See_Also ##### -->
88 <term>#GtkEntry</term>
89 <listitem><para>retrieve text rather than numbers.</para></listitem>
94 <!-- ##### STRUCT GtkSpinButton ##### -->
96 <structfield>entry</structfield> is the #GtkEntry part of the #GtkSpinButton widget, and can be used accordingly. All other fields contain private data and should only be modified using the functions below.
100 <!-- ##### ENUM GtkSpinButtonUpdatePolicy ##### -->
103 <informaltable pgwide=1 frame="none" role="enum">
104 <tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
107 <entry>GTK_UPDATE_ALWAYS</entry>
108 <entry>When refreshing your #GtkSpinButton, the value is always displayed.</entry>
111 <entry>GTK_UPDATE_IF_VALID</entry>
112 <entry>When refreshing your #GtkSpinButton, the value is only displayed if it is valid within the bounds of the spin button's #GtkAdjustment.</entry>
114 </tbody></tgroup></informaltable>
118 @GTK_UPDATE_IF_VALID:
120 <!-- ##### ENUM GtkSpinType ##### -->
123 <informaltable pgwide=1 frame="none" role="struct">
124 <tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
127 <entry>GTK_SPIN_STEP_FORWARD,
128 GTK_SPIN_STEP_BACKWARD,
129 GTK_SPIN_PAGE_FORWARD,
130 GTK_SPIN_PAGE_BACKWARD</entry>
131 <entry>These values spin a #GtkSpinButton by the relevant values of the spin button's #GtkAdjustment.</entry>
134 <entry>GTK_SPIN_HOME,
136 <entry>These set the spin button's value to the minimum or maxmimum possible values, (set by it's #GtkAdjustment), respectively.</entry>
139 <entry>GTK_SPIN_USER_DEFINED</entry>
140 <entry>The programmer must specify the exact amount to spin the #GtkSpinButton.</entry>
142 </tbody></tgroup></informaltable>
145 @GTK_SPIN_STEP_FORWARD:
146 @GTK_SPIN_STEP_BACKWARD:
147 @GTK_SPIN_PAGE_FORWARD:
148 @GTK_SPIN_PAGE_BACKWARD:
151 @GTK_SPIN_USER_DEFINED:
153 <!-- ##### FUNCTION gtk_spin_button_configure ##### -->
155 Changes the properties of an existing spin button. The adjustment, climb rate, and number of decimal places are all changed accordingly, after this function call.
158 @spin_button: a #GtkSpinButton.
159 @adjustment: a #GtkAdjustment.
160 @climb_rate: the new climb rate.
161 @digits: the number of decimal places to display in the spin button.
164 <!-- ##### FUNCTION gtk_spin_button_new ##### -->
166 Creates a new #GtkSpinButton.
169 @adjustment: the #GtkAdjustment object that this spin button should use.
170 @climb_rate: specifies how much the spin button changes when an arrow is clicked on.
171 @digits: the number of decimal places to display.
172 @Returns: The new spin button as a #GtkWidget.
175 <!-- ##### FUNCTION gtk_spin_button_new_with_range ##### -->
186 <!-- ##### FUNCTION gtk_spin_button_set_adjustment ##### -->
195 <!-- ##### FUNCTION gtk_spin_button_get_adjustment ##### -->
204 <!-- ##### FUNCTION gtk_spin_button_set_digits ##### -->
213 <!-- ##### FUNCTION gtk_spin_button_set_increments ##### -->
223 <!-- ##### FUNCTION gtk_spin_button_set_range ##### -->
233 <!-- ##### MACRO gtk_spin_button_get_value_as_float ##### -->
235 Gets the value in the @spin_button. This function is deprecated,
236 use gtk_spin_button_get_value() instead.
239 @Returns: the value of @spin_button.
240 <!-- # Unused Parameters # -->
241 @spin_button: a #GtkSpinButton.
244 <!-- ##### FUNCTION gtk_spin_button_get_value_as_int ##### -->
253 <!-- ##### FUNCTION gtk_spin_button_set_value ##### -->
262 <!-- ##### FUNCTION gtk_spin_button_set_update_policy ##### -->
271 <!-- ##### FUNCTION gtk_spin_button_set_numeric ##### -->
280 <!-- ##### FUNCTION gtk_spin_button_spin ##### -->
290 <!-- ##### FUNCTION gtk_spin_button_set_wrap ##### -->
299 <!-- ##### FUNCTION gtk_spin_button_set_snap_to_ticks ##### -->
308 <!-- ##### FUNCTION gtk_spin_button_update ##### -->
316 <!-- ##### FUNCTION gtk_spin_button_get_digits ##### -->
325 <!-- ##### FUNCTION gtk_spin_button_get_increments ##### -->
335 <!-- ##### FUNCTION gtk_spin_button_get_numeric ##### -->
344 <!-- ##### FUNCTION gtk_spin_button_get_range ##### -->
354 <!-- ##### FUNCTION gtk_spin_button_get_snap_to_ticks ##### -->
363 <!-- ##### FUNCTION gtk_spin_button_get_update_policy ##### -->
372 <!-- ##### FUNCTION gtk_spin_button_get_value ##### -->
381 <!-- ##### FUNCTION gtk_spin_button_get_wrap ##### -->
390 <!-- ##### MACRO GTK_INPUT_ERROR ##### -->
397 <!-- ##### SIGNAL GtkSpinButton::input ##### -->
402 @spinbutton: the object which received the signal.
406 <!-- ##### SIGNAL GtkSpinButton::output ##### -->
411 @spinbutton: the object which received the signal.
414 <!-- ##### SIGNAL GtkSpinButton::value-changed ##### -->
419 @spinbutton: the object which received the signal.
421 <!-- ##### ARG GtkSpinButton:adjustment ##### -->
423 the #GtkAdjustment that defines a spin button's main properties.
426 <!-- ##### ARG GtkSpinButton:climb-rate ##### -->
428 the amount a spin button changes when an arrow is clicked.
431 <!-- ##### ARG GtkSpinButton:digits ##### -->
433 the number of decimal places to display.
436 <!-- ##### ARG GtkSpinButton:snap-to-ticks ##### -->
438 whether erroneous values are automatically changed to a spin button's nearest step increment.
441 <!-- ##### ARG GtkSpinButton:numeric ##### -->
443 whether non-numeric characters should be ignored.
446 <!-- ##### ARG GtkSpinButton:wrap ##### -->
448 whether a spin button should wrap upon reaching its limits.
451 <!-- ##### ARG GtkSpinButton:update-policy ##### -->
453 how a spin button should be updated.
456 <!-- ##### ARG GtkSpinButton:value ##### -->
458 reads the current value, or sets a new value.