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
10 attribute. Rather than having to directly type a number into a #GtkEntry,
11 #GtkSpinButton allows the user to click on one of two arrows to increment or
12 decrement the displayed value. A value can still be typed in, with the bonus
13 that it can be checked to ensure it is in a given range.
16 The main properties of a #GtkSpinButton are through a #GtkAdjustment. See the
17 #GtkAdjustment section for more details about an adjustment's properties.
21 <title>Using a <structname>GtkSpinButton</structname> to get an integer.</title>
24 /* Provides a function to retrieve an integer value from a GtkSpinButton
25 * and creates a spin button to model percentage values.
28 gint grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
29 return gtk_spin_button_get_value_as_int (a_spinner);
32 void create_integer_spin_button (void) {
34 GtkWidget *window, *spinner;
35 GtkAdjustment *spinner_adj;
37 spinner_adj = (GtkAdjustment *) gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 5.0);
39 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
40 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
42 /* creates the spinner, with no decimal places */
43 spinner = gtk_spin_button_new (spinner_adj, 1.0, 0);
44 gtk_container_add (GTK_CONTAINER (window), spinner);
46 gtk_widget_show_all (window);
56 <title>Using a <structname>GtkSpinButton</structname> to get a floating point value.</title>
59 /* Provides a function to retrieve a floating point value from a
60 * GtkSpinButton, and creates a high precision spin button.
63 gfloat grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
64 return gtk_spin_button_get_value (a_spinner);
67 void create_floating_spin_button (void) {
69 GtkWidget *window, *spinner;
70 GtkAdjustment *spinner_adj;
72 spinner_adj = (GtkAdjustment *) gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.1);
74 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
75 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
77 /* creates the spinner, with three decimal places */
78 spinner = gtk_spin_button_new (spinner_adj, 0.001, 3);
79 gtk_container_add (GTK_CONTAINER (window), spinner);
81 gtk_widget_show_all (window);
89 <!-- ##### SECTION See_Also ##### -->
93 <term>#GtkEntry</term>
94 <listitem><para>retrieve text rather than numbers.</para></listitem>
99 <!-- ##### STRUCT GtkSpinButton ##### -->
101 <structfield>entry</structfield> is the #GtkEntry part of the #GtkSpinButton
102 widget, and can be used accordingly. All other fields contain private data
103 and should only be modified using the functions below.
107 <!-- ##### ENUM GtkSpinButtonUpdatePolicy ##### -->
110 <informaltable pgwide="1" frame="none" role="enum">
111 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
114 <entry>GTK_UPDATE_ALWAYS</entry>
115 <entry>When refreshing your #GtkSpinButton, the value is always displayed.</entry>
118 <entry>GTK_UPDATE_IF_VALID</entry>
119 <entry>When refreshing your #GtkSpinButton, the value is only displayed if it is valid within the bounds of the spin button's #GtkAdjustment.</entry>
121 </tbody></tgroup></informaltable>
125 @GTK_UPDATE_IF_VALID:
127 <!-- ##### ENUM GtkSpinType ##### -->
130 <informaltable pgwide="1" frame="none" role="struct">
131 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
134 <entry>GTK_SPIN_STEP_FORWARD,
135 GTK_SPIN_STEP_BACKWARD,
136 GTK_SPIN_PAGE_FORWARD,
137 GTK_SPIN_PAGE_BACKWARD</entry>
138 <entry>These values spin a #GtkSpinButton by the relevant values of the spin button's #GtkAdjustment.</entry>
141 <entry>GTK_SPIN_HOME,
143 <entry>These set the spin button's value to the minimum or maxmimum possible values, (set by its #GtkAdjustment), respectively.</entry>
146 <entry>GTK_SPIN_USER_DEFINED</entry>
147 <entry>The programmer must specify the exact amount to spin the #GtkSpinButton.</entry>
149 </tbody></tgroup></informaltable>
152 @GTK_SPIN_STEP_FORWARD:
153 @GTK_SPIN_STEP_BACKWARD:
154 @GTK_SPIN_PAGE_FORWARD:
155 @GTK_SPIN_PAGE_BACKWARD:
158 @GTK_SPIN_USER_DEFINED:
160 <!-- ##### FUNCTION gtk_spin_button_configure ##### -->
162 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.
165 @spin_button: a #GtkSpinButton.
166 @adjustment: a #GtkAdjustment.
167 @climb_rate: the new climb rate.
168 @digits: the number of decimal places to display in the spin button.
171 <!-- ##### FUNCTION gtk_spin_button_new ##### -->
173 Creates a new #GtkSpinButton.
176 @adjustment: the #GtkAdjustment object that this spin button should use.
177 @climb_rate: specifies how much the spin button changes when an arrow is clicked on.
178 @digits: the number of decimal places to display.
179 @Returns: The new spin button as a #GtkWidget.
182 <!-- ##### FUNCTION gtk_spin_button_new_with_range ##### -->
193 <!-- ##### FUNCTION gtk_spin_button_set_adjustment ##### -->
202 <!-- ##### FUNCTION gtk_spin_button_get_adjustment ##### -->
211 <!-- ##### FUNCTION gtk_spin_button_set_digits ##### -->
220 <!-- ##### FUNCTION gtk_spin_button_set_increments ##### -->
230 <!-- ##### FUNCTION gtk_spin_button_set_range ##### -->
240 <!-- ##### MACRO gtk_spin_button_get_value_as_float ##### -->
242 Gets the value in the @spin_button. This function is deprecated,
243 use gtk_spin_button_get_value() instead.
246 @Returns: the value of @spin_button.
247 <!-- # Unused Parameters # -->
248 @spin_button: a #GtkSpinButton.
251 <!-- ##### FUNCTION gtk_spin_button_get_value_as_int ##### -->
260 <!-- ##### FUNCTION gtk_spin_button_set_value ##### -->
269 <!-- ##### FUNCTION gtk_spin_button_set_update_policy ##### -->
278 <!-- ##### FUNCTION gtk_spin_button_set_numeric ##### -->
287 <!-- ##### FUNCTION gtk_spin_button_spin ##### -->
297 <!-- ##### FUNCTION gtk_spin_button_set_wrap ##### -->
306 <!-- ##### FUNCTION gtk_spin_button_set_snap_to_ticks ##### -->
315 <!-- ##### FUNCTION gtk_spin_button_update ##### -->
323 <!-- ##### FUNCTION gtk_spin_button_get_digits ##### -->
332 <!-- ##### FUNCTION gtk_spin_button_get_increments ##### -->
342 <!-- ##### FUNCTION gtk_spin_button_get_numeric ##### -->
351 <!-- ##### FUNCTION gtk_spin_button_get_range ##### -->
361 <!-- ##### FUNCTION gtk_spin_button_get_snap_to_ticks ##### -->
370 <!-- ##### FUNCTION gtk_spin_button_get_update_policy ##### -->
379 <!-- ##### FUNCTION gtk_spin_button_get_value ##### -->
388 <!-- ##### FUNCTION gtk_spin_button_get_wrap ##### -->
397 <!-- ##### MACRO GTK_INPUT_ERROR ##### -->
404 <!-- ##### SIGNAL GtkSpinButton::change-value ##### -->
409 @spinbutton: the object which received the signal.
412 <!-- ##### SIGNAL GtkSpinButton::input ##### -->
417 @spinbutton: the object which received the signal.
421 <!-- ##### SIGNAL GtkSpinButton::output ##### -->
426 @spinbutton: the object which received the signal.
429 <!-- ##### SIGNAL GtkSpinButton::value-changed ##### -->
434 @spinbutton: the object which received the signal.
436 <!-- ##### ARG GtkSpinButton:adjustment ##### -->
441 <!-- ##### ARG GtkSpinButton:climb-rate ##### -->
446 <!-- ##### ARG GtkSpinButton:digits ##### -->
451 <!-- ##### ARG GtkSpinButton:numeric ##### -->
456 <!-- ##### ARG GtkSpinButton:snap-to-ticks ##### -->
461 <!-- ##### ARG GtkSpinButton:update-policy ##### -->
466 <!-- ##### ARG GtkSpinButton:value ##### -->
471 <!-- ##### ARG GtkSpinButton:wrap ##### -->
476 <!-- ##### ARG GtkSpinButton:shadow-type ##### -->
478 the type of border that surrounds the arrows of a spin button.