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 <!-- ##### SECTION Stability_Level ##### -->
102 <!-- ##### SECTION Image ##### -->
105 <!-- ##### STRUCT GtkSpinButton ##### -->
107 <structfield>entry</structfield> is the #GtkEntry part of the #GtkSpinButton
108 widget, and can be used accordingly. All other fields contain private data
109 and should only be modified using the functions below.
113 <!-- ##### SIGNAL GtkSpinButton::change-value ##### -->
118 @spinbutton: the object which received the signal.
121 <!-- ##### SIGNAL GtkSpinButton::input ##### -->
126 @spinbutton: the object which received the signal.
130 <!-- ##### SIGNAL GtkSpinButton::output ##### -->
135 @spinbutton: the object which received the signal.
138 <!-- ##### SIGNAL GtkSpinButton::value-changed ##### -->
143 @spinbutton: the object which received the signal.
145 <!-- ##### SIGNAL GtkSpinButton::wrapped ##### -->
150 @spinbutton: the object which received the signal.
152 <!-- ##### ARG GtkSpinButton:adjustment ##### -->
157 <!-- ##### ARG GtkSpinButton:climb-rate ##### -->
162 <!-- ##### ARG GtkSpinButton:digits ##### -->
167 <!-- ##### ARG GtkSpinButton:numeric ##### -->
172 <!-- ##### ARG GtkSpinButton:snap-to-ticks ##### -->
177 <!-- ##### ARG GtkSpinButton:update-policy ##### -->
182 <!-- ##### ARG GtkSpinButton:value ##### -->
187 <!-- ##### ARG GtkSpinButton:wrap ##### -->
192 <!-- ##### ARG GtkSpinButton:shadow-type ##### -->
194 the type of border that surrounds the arrows of a spin button.
197 <!-- ##### ENUM GtkSpinButtonUpdatePolicy ##### -->
200 <informaltable pgwide="1" frame="none" role="enum">
201 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
204 <entry>GTK_UPDATE_ALWAYS</entry>
205 <entry>When refreshing your #GtkSpinButton, the value is always displayed.</entry>
208 <entry>GTK_UPDATE_IF_VALID</entry>
209 <entry>When refreshing your #GtkSpinButton, the value is only displayed if it is valid within the bounds of the spin button's #GtkAdjustment.</entry>
211 </tbody></tgroup></informaltable>
215 @GTK_UPDATE_IF_VALID:
217 <!-- ##### ENUM GtkSpinType ##### -->
220 <informaltable pgwide="1" frame="none" role="struct">
221 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
224 <entry>GTK_SPIN_STEP_FORWARD,
225 GTK_SPIN_STEP_BACKWARD,
226 GTK_SPIN_PAGE_FORWARD,
227 GTK_SPIN_PAGE_BACKWARD</entry>
228 <entry>These values spin a #GtkSpinButton by the relevant values of the spin button's #GtkAdjustment.</entry>
231 <entry>GTK_SPIN_HOME,
233 <entry>These set the spin button's value to the minimum or maxmimum possible values, (set by its #GtkAdjustment), respectively.</entry>
236 <entry>GTK_SPIN_USER_DEFINED</entry>
237 <entry>The programmer must specify the exact amount to spin the #GtkSpinButton.</entry>
239 </tbody></tgroup></informaltable>
242 @GTK_SPIN_STEP_FORWARD:
243 @GTK_SPIN_STEP_BACKWARD:
244 @GTK_SPIN_PAGE_FORWARD:
245 @GTK_SPIN_PAGE_BACKWARD:
248 @GTK_SPIN_USER_DEFINED:
250 <!-- ##### FUNCTION gtk_spin_button_configure ##### -->
261 <!-- ##### FUNCTION gtk_spin_button_new ##### -->
263 Creates a new #GtkSpinButton.
266 @adjustment: the #GtkAdjustment object that this spin button should use.
267 @climb_rate: specifies how much the spin button changes when an arrow is clicked on.
268 @digits: the number of decimal places to display.
269 @Returns: The new spin button as a #GtkWidget.
272 <!-- ##### FUNCTION gtk_spin_button_new_with_range ##### -->
283 <!-- ##### FUNCTION gtk_spin_button_set_adjustment ##### -->
292 <!-- ##### FUNCTION gtk_spin_button_get_adjustment ##### -->
301 <!-- ##### FUNCTION gtk_spin_button_set_digits ##### -->
310 <!-- ##### FUNCTION gtk_spin_button_set_increments ##### -->
320 <!-- ##### FUNCTION gtk_spin_button_set_range ##### -->
330 <!-- ##### FUNCTION gtk_spin_button_get_value_as_int ##### -->
339 <!-- ##### FUNCTION gtk_spin_button_set_value ##### -->
348 <!-- ##### FUNCTION gtk_spin_button_set_update_policy ##### -->
357 <!-- ##### FUNCTION gtk_spin_button_set_numeric ##### -->
366 <!-- ##### FUNCTION gtk_spin_button_spin ##### -->
376 <!-- ##### FUNCTION gtk_spin_button_set_wrap ##### -->
385 <!-- ##### FUNCTION gtk_spin_button_set_snap_to_ticks ##### -->
394 <!-- ##### FUNCTION gtk_spin_button_update ##### -->
402 <!-- ##### FUNCTION gtk_spin_button_get_digits ##### -->
411 <!-- ##### FUNCTION gtk_spin_button_get_increments ##### -->
421 <!-- ##### FUNCTION gtk_spin_button_get_numeric ##### -->
430 <!-- ##### FUNCTION gtk_spin_button_get_range ##### -->
440 <!-- ##### FUNCTION gtk_spin_button_get_snap_to_ticks ##### -->
449 <!-- ##### FUNCTION gtk_spin_button_get_update_policy ##### -->
458 <!-- ##### FUNCTION gtk_spin_button_get_value ##### -->
467 <!-- ##### FUNCTION gtk_spin_button_get_wrap ##### -->
476 <!-- ##### MACRO GTK_INPUT_ERROR ##### -->