Retrieve an integer or floating-point number from the user
A <gtk-spin-button>
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
<gtk-entry>
, <gtk-spin-button>
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.
The main properties of a <gtk-spin-button>
are through a
<gtk-adjustment>
. See the <gtk-adjustment>
section for more
details about an adjustment's properties.
/* Provides a function to retrieve an integer value from a GtkSpinButton * and creates a spin button to model percentage values. */ gint grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) { return gtk_spin_button_get_value_as_int (a_spinner); } void create_integer_spin_button (void) { GtkWidget *window, *spinner; GtkAdjustment *spinner_adj; spinner_adj = (GtkAdjustment *) gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 5.0); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); /* creates the spinner, with no decimal places */ spinner = gtk_spin_button_new (spinner_adj, 1.0, 0); gtk_container_add (GTK_CONTAINER (window), spinner); gtk_widget_show_all (window); return; }
/* Provides a function to retrieve a floating point value from a * GtkSpinButton, and creates a high precision spin button. */ gfloat grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) { return gtk_spin_button_get_value (a_spinner); } void create_floating_spin_button (void) { GtkWidget *window, *spinner; GtkAdjustment *spinner_adj; spinner_adj = (GtkAdjustment *) gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.1); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); /* creates the spinner, with three decimal places */ spinner = gtk_spin_button_new (spinner_adj, 0.001, 3); gtk_container_add (GTK_CONTAINER (window), spinner); gtk_widget_show_all (window); return; }
Derives from
<gtk-entry>
.This class defines the following slots:
adjustment
- The adjustment that holds the value of the spinbutton
climb-rate
- The acceleration rate when you hold down a button
digits
- The number of decimal places to display
snap-to-ticks
- Whether erroneous values are automatically changed to a spin button's nearest step increment
numeric
- Whether non-numeric characters should be ignored
wrap
- Whether a spin button should wrap upon reaching its limits
update-policy
- Whether the spin button should update always, or only when the value is legal
value
- Reads the current value, or sets a new value
The wrapped signal is emitted right after the spinbutton wraps from its maximum to minimum value or vice-versa.
Since 2.10
<gtk-spin-button>
) (adjustment <gtk-adjustment>
) (climb_rate double
) (digits unsigned-int
)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.
- spin-button
- a
<gtk-spin-button>
.- adjustment
- a
<gtk-adjustment>
.- climb-rate
- the new climb rate.
- digits
- the number of decimal places to display in the spin button.
<gtk-adjustment>
) (climb_rate double
) (digits unsigned-int
) ⇒ (ret <gtk-widget>
)Creates a new
<gtk-spin-button>
.
- adjustment
- the
<gtk-adjustment>
object that this spin button should use.- climb-rate
- specifies how much the spin button changes when an arrow is clicked on.
- digits
- the number of decimal places to display.
- ret
- The new spin button as a
<gtk-widget>
.
double
) (max double
) (step double
) ⇒ (ret <gtk-widget>
)This is a convenience constructor that allows creation of a numeric
<gtk-spin-button>
without manually creating an adjustment. The value is initially set to the minimum value and a page increment of 10 * step is the default. The precision of the spin button is equivalent to the precision of step.Note that the way in which the precision is derived works best if step is a power of ten. If the resulting precision is not suitable for your needs, use
gtk-spin-button-set-digits
to correct it.
- min
- Minimum allowable value
- max
- Maximum allowable value
- step
- Increment added or subtracted by spinning the widget
- ret
- The new spin button as a
<gtk-widget>
.
<gtk-spin-button>
) (adjustment <gtk-adjustment>
)Replaces the
<gtk-adjustment>
associated with spin-button.
- spin-button
- a
<gtk-spin-button>
- adjustment
- a
<gtk-adjustment>
to replace the existing adjustment
<gtk-spin-button>
) ⇒ (ret <gtk-adjustment>
)Get the adjustment associated with a
<gtk-spin-button>
- spin-button
- a
<gtk-spin-button>
- ret
- the
<gtk-adjustment>
of spin-button
<gtk-spin-button>
) (digits unsigned-int
)Set the precision to be displayed by spin-button. Up to 20 digit precision is allowed.
- spin-button
- a
<gtk-spin-button>
- digits
- the number of digits after the decimal point to be displayed for the spin button's value
<gtk-spin-button>
) (step double
) (page double
)Sets the step and page increments for spin_button. This affects how quickly the value changes when the spin button's arrows are activated.
- spin-button
- a
<gtk-spin-button>
- step
- increment applied for a button 1 press.
- page
- increment applied for a button 2 press.
<gtk-spin-button>
) (min double
) (max double
)Sets the minimum and maximum allowable values for spin-button
- spin-button
- a
<gtk-spin-button>
- min
- minimum allowable value
- max
- maximum allowable value
<gtk-spin-button>
) ⇒ (ret int
)Get the value spin-button represented as an integer.
- spin-button
- a
<gtk-spin-button>
- ret
- the value of spin-button
<gtk-spin-button>
) (value double
)Set the value of spin-button.
- spin-button
- a
<gtk-spin-button>
- value
- the new value
<gtk-spin-button>
) (policy <gtk-spin-button-update-policy>
)Sets the update behavior of a spin button. This determines whether the spin button is always updated or only when a valid value is set.
- spin-button
- a
<gtk-spin-button>
- policy
- a
<gtk-spin-button-update-policy>
value
<gtk-spin-button>
) (numeric bool
)Sets the flag that determines if non-numeric text can be typed into the spin button.
- spin-button
- a
<gtk-spin-button>
- numeric
- flag indicating if only numeric entry is allowed.
<gtk-spin-button>
) (direction <gtk-spin-type>
) (increment double
)Increment or decrement a spin button's value in a specified direction by a specified amount.
- spin-button
- a
<gtk-spin-button>
- direction
- a
<gtk-spin-type>
indicating the direction to spin.- increment
- step increment to apply in the specified direction.
<gtk-spin-button>
) (wrap bool
)Sets the flag that determines if a spin button value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.
- spin-button
- a
<gtk-spin-button>
- wrap
- a flag indicating if wrapping behavior is performed.
<gtk-spin-button>
) (snap_to_ticks bool
)Sets the policy as to whether values are corrected to the nearest step increment when a spin button is activated after providing an invalid value.
- spin-button
- a
<gtk-spin-button>
- snap-to-ticks
- a flag indicating if invalid values should be corrected.
<gtk-spin-button>
)Manually force an update of the spin button.
- spin-button
- a
<gtk-spin-button>
<gtk-spin-button>
) ⇒ (ret unsigned-int
)Fetches the precision of spin-button. See
gtk-spin-button-set-digits
.
- spin-button
- a
<gtk-spin-button>
- ret
- the current precision
<gtk-spin-button>
) ⇒ (step double
) (page double
)Gets the current step and page the increments used by spin-button. See
gtk-spin-button-set-increments
.
- spin-button
- a
<gtk-spin-button>
- step
- location to store step increment, or ‘
#f
’- page
- location to store page increment, or ‘
#f
’
<gtk-spin-button>
) ⇒ (ret bool
)Returns whether non-numeric text can be typed into the spin button. See
gtk-spin-button-set-numeric
.
- spin-button
- a
<gtk-spin-button>
- ret
- ‘
#t
’ if only numeric text can be entered
<gtk-spin-button>
) ⇒ (min double
) (max double
)Gets the range allowed for spin-button. See
gtk-spin-button-set-range
.
- spin-button
- a
<gtk-spin-button>
- min
- location to store minimum allowed value, or ‘
#f
’- max
- location to store maximum allowed value, or ‘
#f
’
<gtk-spin-button>
) ⇒ (ret bool
)Returns whether the values are corrected to the nearest step. See
gtk-spin-button-set-snap-to-ticks
.
- spin-button
- a
<gtk-spin-button>
- ret
- ‘
#t
’ if values are snapped to the nearest step.
<gtk-spin-button>
) ⇒ (ret double
)Get the value in the spin-button.
- spin-button
- a
<gtk-spin-button>
- ret
- the value of spin-button
<gtk-spin-button>
) ⇒ (ret bool
)Returns whether the spin button's value wraps around to the opposite limit when the upper or lower limit of the range is exceeded. See
gtk-spin-button-set-wrap
.
- spin-button
- a
<gtk-spin-button>
- ret
- ‘
#t
’ if the spin button wraps around