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 <!-- ##### STRUCT GtkSpinButton ##### -->
104 <structfield>entry</structfield> is the #GtkEntry part of the #GtkSpinButton
105 widget, and can be used accordingly. All other fields contain private data
106 and should only be modified using the functions below.
110 <!-- ##### SIGNAL GtkSpinButton::change-value ##### -->
115 @spinbutton: the object which received the signal.
118 <!-- ##### SIGNAL GtkSpinButton::input ##### -->
123 @spinbutton: the object which received the signal.
127 <!-- ##### SIGNAL GtkSpinButton::output ##### -->
132 @spinbutton: the object which received the signal.
135 <!-- ##### SIGNAL GtkSpinButton::value-changed ##### -->
140 @spinbutton: the object which received the signal.
142 <!-- ##### SIGNAL GtkSpinButton::wrapped ##### -->
147 @spinbutton: the object which received the signal.
149 <!-- ##### ARG GtkSpinButton:adjustment ##### -->
154 <!-- ##### ARG GtkSpinButton:climb-rate ##### -->
159 <!-- ##### ARG GtkSpinButton:digits ##### -->
164 <!-- ##### ARG GtkSpinButton:numeric ##### -->
169 <!-- ##### ARG GtkSpinButton:snap-to-ticks ##### -->
174 <!-- ##### ARG GtkSpinButton:update-policy ##### -->
179 <!-- ##### ARG GtkSpinButton:value ##### -->
184 <!-- ##### ARG GtkSpinButton:wrap ##### -->
189 <!-- ##### ARG GtkSpinButton:shadow-type ##### -->
191 the type of border that surrounds the arrows of a spin button.
194 <!-- ##### ENUM GtkSpinButtonUpdatePolicy ##### -->
197 <informaltable pgwide="1" frame="none" role="enum">
198 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
201 <entry>GTK_UPDATE_ALWAYS</entry>
202 <entry>When refreshing your #GtkSpinButton, the value is always displayed.</entry>
205 <entry>GTK_UPDATE_IF_VALID</entry>
206 <entry>When refreshing your #GtkSpinButton, the value is only displayed if it is valid within the bounds of the spin button's #GtkAdjustment.</entry>
208 </tbody></tgroup></informaltable>
212 @GTK_UPDATE_IF_VALID:
214 <!-- ##### ENUM GtkSpinType ##### -->
217 <informaltable pgwide="1" frame="none" role="struct">
218 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
221 <entry>GTK_SPIN_STEP_FORWARD,
222 GTK_SPIN_STEP_BACKWARD,
223 GTK_SPIN_PAGE_FORWARD,
224 GTK_SPIN_PAGE_BACKWARD</entry>
225 <entry>These values spin a #GtkSpinButton by the relevant values of the spin button's #GtkAdjustment.</entry>
228 <entry>GTK_SPIN_HOME,
230 <entry>These set the spin button's value to the minimum or maxmimum possible values, (set by its #GtkAdjustment), respectively.</entry>
233 <entry>GTK_SPIN_USER_DEFINED</entry>
234 <entry>The programmer must specify the exact amount to spin the #GtkSpinButton.</entry>
236 </tbody></tgroup></informaltable>
239 @GTK_SPIN_STEP_FORWARD:
240 @GTK_SPIN_STEP_BACKWARD:
241 @GTK_SPIN_PAGE_FORWARD:
242 @GTK_SPIN_PAGE_BACKWARD:
245 @GTK_SPIN_USER_DEFINED:
247 <!-- ##### FUNCTION gtk_spin_button_configure ##### -->
249 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.
252 @spin_button: a #GtkSpinButton.
253 @adjustment: a #GtkAdjustment.
254 @climb_rate: the new climb rate.
255 @digits: the number of decimal places to display in the spin button.
258 <!-- ##### FUNCTION gtk_spin_button_new ##### -->
260 Creates a new #GtkSpinButton.
263 @adjustment: the #GtkAdjustment object that this spin button should use.
264 @climb_rate: specifies how much the spin button changes when an arrow is clicked on.
265 @digits: the number of decimal places to display.
266 @Returns: The new spin button as a #GtkWidget.
269 <!-- ##### FUNCTION gtk_spin_button_new_with_range ##### -->
280 <!-- ##### FUNCTION gtk_spin_button_set_adjustment ##### -->
289 <!-- ##### FUNCTION gtk_spin_button_get_adjustment ##### -->
298 <!-- ##### FUNCTION gtk_spin_button_set_digits ##### -->
307 <!-- ##### FUNCTION gtk_spin_button_set_increments ##### -->
317 <!-- ##### FUNCTION gtk_spin_button_set_range ##### -->
327 <!-- ##### MACRO gtk_spin_button_get_value_as_float ##### -->
329 Gets the value in the @spin_button. This function is deprecated,
330 use gtk_spin_button_get_value() instead.
333 @Returns: the value of @spin_button.
334 <!-- # Unused Parameters # -->
335 @spin_button: a #GtkSpinButton.
338 <!-- ##### FUNCTION gtk_spin_button_get_value_as_int ##### -->
347 <!-- ##### FUNCTION gtk_spin_button_set_value ##### -->
356 <!-- ##### FUNCTION gtk_spin_button_set_update_policy ##### -->
365 <!-- ##### FUNCTION gtk_spin_button_set_numeric ##### -->
374 <!-- ##### FUNCTION gtk_spin_button_spin ##### -->
384 <!-- ##### FUNCTION gtk_spin_button_set_wrap ##### -->
393 <!-- ##### FUNCTION gtk_spin_button_set_snap_to_ticks ##### -->
402 <!-- ##### FUNCTION gtk_spin_button_update ##### -->
410 <!-- ##### FUNCTION gtk_spin_button_get_digits ##### -->
419 <!-- ##### FUNCTION gtk_spin_button_get_increments ##### -->
429 <!-- ##### FUNCTION gtk_spin_button_get_numeric ##### -->
438 <!-- ##### FUNCTION gtk_spin_button_get_range ##### -->
448 <!-- ##### FUNCTION gtk_spin_button_get_snap_to_ticks ##### -->
457 <!-- ##### FUNCTION gtk_spin_button_get_update_policy ##### -->
466 <!-- ##### FUNCTION gtk_spin_button_get_value ##### -->
475 <!-- ##### FUNCTION gtk_spin_button_get_wrap ##### -->
484 <!-- ##### MACRO GTK_INPUT_ERROR ##### -->