It derives from <GtkWidget>.
Allows to enter or change numeric values.
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.
The main properties of a <GtkSpinButton> are
through an adjustment. See the <GtkAdjustment>
documentation for more details about an adjustment’s properties.
Note that <GtkSpinButton> will by default make
its entry large enough to accommodate the lower and upper bounds of the
adjustment. If this is not desired, the automatic sizing can be turned
off by explicitly setting editable:width-chars to a value != -1.
// Provides a function to retrieve an integer value from a GtkSpinButton
// and creates a spin button to model percentage values.
int
grab_int_value (GtkSpinButton *button,
gpointer user_data)
{
return gtk_spin_button_get_value_as_int (button);
}
void
create_integer_spin_button (void)
{
GtkWidget *window, *button;
GtkAdjustment *adjustment;
adjustment = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0);
window = gtk_window_new ();
// creates the spinbutton, with no decimal places
button = gtk_spin_button_new (adjustment, 1.0, 0);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
// Provides a function to retrieve a floating point value from a
// GtkSpinButton, and creates a high precision spin button.
float
grab_float_value (GtkSpinButton *button,
gpointer user_data)
{
return gtk_spin_button_get_value (button);
}
void
create_floating_spin_button (void)
{
GtkWidget *window, *button;
GtkAdjustment *adjustment;
adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0);
window = gtk_window_new ();
// creates the spinbutton, with three decimal places
button = gtk_spin_button_new (adjustment, 0.001, 3);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
The following signals have default keybindings:
spinbutton.horizontal ├── text │ ├── undershoot.left │ ╰── undershoot.right ├── button.down ╰── button.up
spinbutton.vertical ├── button.up ├── text │ ├── undershoot.left │ ╰── undershoot.right ╰── button.down
<GtkSpinButton>s main CSS node has the name
spinbutton. It creates subnodes for the entry and the two buttons, with
these names. The button nodes have the style classes .up and .down. The
<GtkText> subnodes (if present) are put below the
text node. The orientation of the spin button is reflected in the
.vertical or .horizontal style class on the main node.
<GtkSpinButton> uses the
Gtk.AccessibleRole.spin_button role.
Whether to activate the default widget when the spin button is activated.
See spin-button:activate for
what counts as activation.
Its value is a boolean.
Set it with (set! (spin-button:activates-default self) value).
The adjustment that holds the value of the spin button.
Its value is a <GtkAdjustment>, or #f.
Set it with (set! (spin-button:adjustment self) value).
The acceleration rate when you hold down a button or key.
Its value is a real number.
Set it with (set! (spin-button:climb-rate self) value).
The number of decimal places to display.
Its value is an unsigned 32-bit integer.
Set it with (set! (spin-button:digits self) value).
Whether non-numeric characters should be ignored.
Its value is a boolean.
Set it with (set! (spin-button:numeric self) value).
Whether erroneous values are automatically changed to the spin buttons nearest step increment.
Its value is a boolean.
Set it with (set! (spin-button:snap-to-ticks self) value).
Whether the spin button should update always, or only when the value is acceptable.
Its value is a
<GtkSpinButtonUpdatePolicy> (or, to
set it, one of its symbols).
Set it with (set! (spin-button:update-policy self) value).
The current value.
Its value is a real number.
Set it with (set! (spin-button:value self) value).
Whether a spin button should wrap upon reaching its limits.
Its value is a boolean.
Set it with (set! (spin-button:wrap self) value).
Changes the properties of an existing spin button.
The adjustment, climb rate, and number of decimal places are updated accordingly.
Passed: a <GtkSpinButton>.
Passed: a <GtkAdjustment>, or #f.
a <GtkAdjustment> to replace the spin button’s
existing adjustment, or #f to leave its current adjustment
unchanged
Passed: a real number.
the new climb rate
Passed: an unsigned 32-bit integer.
the number of decimal places to display in the spin button
Retrieves the value set by spin-button:set-activates-default.
Passed: a <GtkSpinButton>.
Returned: a boolean.
#t if the spin button will activate the default widget
Get the adjustment associated with a
<GtkSpinButton>.
Passed: a <GtkSpinButton>.
Returned: a <GtkAdjustment>.
the <GtkAdjustment> of self
Returns the acceleration rate for repeated changes.
Passed: a <GtkSpinButton>.
Returned: a real number.
the acceleration rate
Fetches the precision of self.
Passed: a <GtkSpinButton>.
Returned: an unsigned 32-bit integer.
the current precision
Gets the current step and page the increments used by self.
See spin-button:set-increments.
Passed: a <GtkSpinButton>.
Returned: a real number.
location to store step increment
Returned: a real number.
location to store page increment
Returns whether non-numeric text can be typed into the spin button.
Passed: a <GtkSpinButton>.
Returned: a boolean.
#t if only numeric text can be entered
Gets the range allowed for self.
Passed: a <GtkSpinButton>.
Returned: a real number.
location to store minimum allowed value
Returned: a real number.
location to store maximum allowed value
Returns whether the values are corrected to the nearest step.
Passed: a <GtkSpinButton>.
Returned: a boolean.
#t if values are snapped to the nearest step
Gets the update behavior of a spin button.
See spin-button:set-update-policy.
Passed: a <GtkSpinButton>.
Returned: a
<GtkSpinButtonUpdatePolicy>.
the current update policy
Get the value in the self.
Passed: a <GtkSpinButton>.
Returned: a real number.
the value of self
Get the value self represented as an integer.
Passed: a <GtkSpinButton>.
Returned: a 32-bit integer.
the value of self
Returns whether the spin button’s value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.
Passed: a <GtkSpinButton>.
Returned: a boolean.
#t if the spin button wraps around
Creates a new <GtkSpinButton>.
Passed: a <GtkAdjustment>, or #f.
the <GtkAdjustment> that this spin button
should use
Passed: a real number.
specifies by how much the rate of change in the value will accelerate if you continue to hold down an up/down button or arrow key
Passed: an unsigned 32-bit integer.
the number of decimal places to display
Returned: a <GtkWidget>.
The new <GtkSpinButton>
Creates a new <GtkSpinButton> with the given
properties.
This is a convenience constructor that allows creation of a numeric
<GtkSpinButton> 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 spin-button:set-digits to correct it.
Passed: a real number.
Minimum allowable value
Passed: a real number.
Maximum allowable value
Passed: a real number.
Increment added or subtracted by spinning the widget
Returned: a <GtkWidget>.
The new <GtkSpinButton>
Sets whether activating the spin button will activate the default widget for the window containing the spin button.
See spin-button:activate for
what counts as activation.
Passed: a <GtkSpinButton>.
Passed: a boolean.
#t to activate window’s default widget on activation
Replaces the <GtkAdjustment> associated with
self.
Passed: a <GtkSpinButton>.
Passed: a <GtkAdjustment>.
a <GtkAdjustment> to replace the existing
adjustment
Sets the acceleration rate for repeated changes when you hold down a button or key.
Passed: a <GtkSpinButton>.
Passed: a real number.
the rate of acceleration, must be >= 0
Set the precision to be displayed by self.
Up to 20 digit precision is allowed.
Passed: a <GtkSpinButton>.
Passed: an unsigned 32-bit integer.
the number of digits after the decimal point to be displayed for the spin button’s value
Sets the step and page increments for spin_button.
This affects how quickly the value changes when the spin button’s arrows are activated.
Passed: a <GtkSpinButton>.
Passed: a real number.
increment applied for a button 1 press.
Passed: a real number.
increment applied for a button 2 press.
Sets the flag that determines if non-numeric text can be typed into the spin button.
Passed: a <GtkSpinButton>.
Passed: a boolean.
flag indicating if only numeric entry is allowed
Sets the minimum and maximum allowable values for self.
If the current value is outside this range, it will be adjusted to fit within the range, otherwise it will remain unchanged.
Passed: a <GtkSpinButton>.
Passed: a real number.
minimum allowable value
Passed: a real number.
maximum allowable value
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.
Passed: a <GtkSpinButton>.
Passed: a boolean.
a flag indicating if invalid values should be corrected
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.
Passed: a <GtkSpinButton>.
Passed: a
<GtkSpinButtonUpdatePolicy>, or one
of its symbols.
a <GtkSpinButtonUpdatePolicy> value
Sets the value of self.
Passed: a <GtkSpinButton>.
Passed: a real number.
the new value
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.
Passed: a <GtkSpinButton>.
Passed: a boolean.
a flag indicating if wrapping behavior is performed
Increment or decrement a spin button’s value in a specified direction by a specified amount.
Passed: a <GtkSpinButton>.
Passed: a <GtkSpinType>, or one of its symbols.
a <GtkSpinType> indicating the direction to spin
Passed: a real number.
step increment to apply in the specified direction
Manually force an update of the spin button.
Passed: a <GtkSpinButton>.
Connect a handler with (connect object spin-button:activate
handler). It is called as (handler self).
Emitted when the spin button is activated.
The keybindings for this signal are all forms of the Enter key.
If the Enter key results in the value being committed to the spin button, then activation does not occur until Enter is pressed again.
Passed: a <GtkSpinButton>.
Connect a handler with (connect object spin-button:change-value
handler). It is called as (handler self scroll).
Emitted when the user initiates a value change.
This is a keybinding signal.
Applications should not connect to it, but may emit it with
g_signal_emit_by_name() if they need to control the cursor
programmatically.
The default bindings for this signal are Up/Down and PageUp/PageDown.
Passed: a <GtkSpinButton>.
Passed: a <GtkScrollType>.
a <GtkScrollType> to specify the speed and
amount of change
Connect a handler with (connect object spin-button:input
handler). It is called as (handler self) ⇒ %return new-value.
Emitted to convert the users input into a double value.
The signal handler is expected to use editable:get-text to retrieve the text of the spinbutton and
set new-value to the new value.
The default conversion uses strtod.
Passed: a <GtkSpinButton>.
Returned: a 32-bit integer.
#t for a successful conversion, #f if the input was not
handled, and GTK_INPUT_ERROR if the conversion failed.
Returned: a real number.
return location for the new value
Connect a handler with (connect object spin-button:output
handler). It is called as (handler self) ⇒ %return.
Emitted to tweak the formatting of the value for display.
// show leading zeros
static gboolean
on_output (GtkSpinButton *spin,
gpointer data)
{
char *text;
int value;
value = gtk_spin_button_get_value_as_int (spin);
text = g_strdup_printf ("%02d", value);
gtk_editable_set_text (GTK_EDITABLE (spin), text):
g_free (text);
return TRUE;
}
Passed: a <GtkSpinButton>.
Returned: a boolean.
#t if the value has been displayed
Connect a handler with (connect object spin-button:value-changed
handler). It is called as (handler self).
Emitted when the value is changed.
Also see the spin-button:output
signal.
Passed: a <GtkSpinButton>.
Connect a handler with (connect object spin-button:wrapped
handler). It is called as (handler self).
Emitted right after the spinbutton wraps from its maximum to its minimum value or vice-versa.
Passed: a <GtkSpinButton>.