Class: Gtk::SpinButton
- Defined in:
- (unknown)
Overview
A GtkSpinButton 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 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 [classGtk.Adjustment] 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 [propertyGtk.Editable:width-chars] to a value != -1.
Using a GtkSpinButton to get an integer
// 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));
}
Using a GtkSpinButton to get a floating point value
// 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));
}
CSS nodes
.horizontal
├── text
│ ├── undershoot.left
│ ╰── undershoot.right
├── .down
╰── .up
.vertical
├── .up
├── text
│ ├── undershoot.left
│ ╰── undershoot.right
╰── .down
GtkSpinButtons 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.
Accessibility
GtkSpinButton uses the %GTK_ACCESSIBLE_ROLE_SPIN_BUTTON role.
Instance Method Summary collapse
-
#activates_default ⇒ Boolean
Retrieves the value set by [methodGtk.SpinButton.set_activates_default].
-
#activates_default=(activates_default) ⇒ Boolean
Whether to activate the default widget when the spin button is activated.
-
#activates_default? ⇒ Boolean
Whether to activate the default widget when the spin button is activated.
-
#adjustment ⇒ Gtk::Adjustment
The adjustment that holds the value of the spin button.
-
#adjustment=(adjustment) ⇒ Gtk::Adjustment
The adjustment that holds the value of the spin button.
-
#climb_rate ⇒ Float
The acceleration rate when you hold down a button or key.
-
#climb_rate=(climb_rate) ⇒ Float
The acceleration rate when you hold down a button or key.
-
#configure(adjustment, climb_rate, digits) ⇒ nil
Changes the properties of an existing spin button.
-
#digits ⇒ Integer
The number of decimal places to display.
-
#digits=(digits) ⇒ Integer
The number of decimal places to display.
-
#get_increments(step, page) ⇒ nil
Gets the current step and page the increments used by spin_button.
-
#get_range(min, max) ⇒ nil
Gets the range allowed for spin_button.
-
#initialize(min, max, step) ⇒ Gtk::Widget
constructor
Creates a new
GtkSpinButtonwith the given properties. -
#numeric ⇒ Boolean
Returns whether non-numeric text can be typed into the spin button.
-
#numeric=(numeric) ⇒ Boolean
Whether non-numeric characters should be ignored.
-
#numeric? ⇒ Boolean
Whether non-numeric characters should be ignored.
-
#set_increments(step, page) ⇒ nil
Sets the step and page increments for spin_button.
-
#set_range(min, max) ⇒ nil
Sets the minimum and maximum allowable values for spin_button.
-
#snap_to_ticks ⇒ Boolean
Returns whether the values are corrected to the nearest step.
-
#snap_to_ticks=(snap_to_ticks) ⇒ Boolean
Whether erroneous values are automatically changed to the spin buttons nearest step increment.
-
#snap_to_ticks? ⇒ Boolean
Whether erroneous values are automatically changed to the spin buttons nearest step increment.
-
#spin(direction, increment) ⇒ nil
Increment or decrement a spin button’s value in a specified direction by a specified amount.
-
#update ⇒ nil
Manually force an update of the spin button.
-
#update_policy ⇒ Gtk::SpinButtonUpdatePolicy
Whether the spin button should update always, or only when the value is acceptable.
-
#update_policy=(update_policy) ⇒ Gtk::SpinButtonUpdatePolicy
Whether the spin button should update always, or only when the value is acceptable.
-
#value ⇒ Float
The current value.
-
#value=(value) ⇒ Float
The current value.
-
#value_as_int ⇒ Integer
Get the value spin_button represented as an integer.
-
#wrap ⇒ Boolean
Returns whether the spin button’s value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.
-
#wrap=(wrap) ⇒ Boolean
Whether a spin button should wrap upon reaching its limits.
-
#wrap? ⇒ Boolean
Whether a spin button should wrap upon reaching its limits.
Methods inherited from Widget
#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_state_flags, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #template=, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=
Constructor Details
#initialize(min, max, step) ⇒ Gtk::Widget
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 [methodGtk.SpinButton.set_digits] to correct it.
Instance Method Details
#activates_default ⇒ Boolean
Retrieves the value set by [methodGtk.SpinButton.set_activates_default].
#activates_default=(activates_default) ⇒ Boolean
Whether to activate the default widget when the spin button is activated.
See [signalGtk.SpinButton::activate] for what counts as activation.
#activates_default? ⇒ Boolean
Whether to activate the default widget when the spin button is activated.
See [signalGtk.SpinButton::activate] for what counts as activation.
#adjustment ⇒ Gtk::Adjustment
The adjustment that holds the value of the spin button.
#adjustment=(adjustment) ⇒ Gtk::Adjustment
The adjustment that holds the value of the spin button.
#climb_rate ⇒ Float
The acceleration rate when you hold down a button or key.
#climb_rate=(climb_rate) ⇒ Float
The acceleration rate when you hold down a button or key.
#configure(adjustment, climb_rate, digits) ⇒ nil
Changes the properties of an existing spin button.
The adjustment, climb rate, and number of decimal places are updated accordingly.
#digits ⇒ Integer
The number of decimal places to display.
#digits=(digits) ⇒ Integer
The number of decimal places to display.
#get_increments(step, page) ⇒ nil
Gets the current step and page the increments used by spin_button.
See [methodGtk.SpinButton.set_increments].
#get_range(min, max) ⇒ nil
Gets the range allowed for spin_button.
See [methodGtk.SpinButton.set_range].
#numeric ⇒ Boolean
Returns whether non-numeric text can be typed into the spin button.
#numeric=(numeric) ⇒ Boolean
Whether non-numeric characters should be ignored.
#numeric? ⇒ Boolean
Whether non-numeric characters should be ignored.
#set_increments(step, page) ⇒ nil
Sets the step and page increments for spin_button.
This affects how quickly the value changes when the spin button’s arrows are activated.
#set_range(min, max) ⇒ nil
Sets the minimum and maximum allowable values for spin_button.
If the current value is outside this range, it will be adjusted to fit within the range, otherwise it will remain unchanged.
#snap_to_ticks ⇒ Boolean
Returns whether the values are corrected to the nearest step.
#snap_to_ticks=(snap_to_ticks) ⇒ Boolean
Whether erroneous values are automatically changed to the spin buttons nearest step increment.
#snap_to_ticks? ⇒ Boolean
Whether erroneous values are automatically changed to the spin buttons nearest step increment.
#spin(direction, increment) ⇒ nil
Increment or decrement a spin button’s value in a specified direction by a specified amount.
#update ⇒ nil
Manually force an update of the spin button.
#update_policy ⇒ Gtk::SpinButtonUpdatePolicy
Whether the spin button should update always, or only when the value is acceptable.
#update_policy=(update_policy) ⇒ Gtk::SpinButtonUpdatePolicy
Whether the spin button should update always, or only when the value is acceptable.
#value ⇒ Float
The current value.
#value=(value) ⇒ Float
The current value.
#value_as_int ⇒ Integer
Get the value spin_button represented as an integer.
#wrap ⇒ Boolean
Returns whether the spin button’s value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.
#wrap=(wrap) ⇒ Boolean
Whether a spin button should wrap upon reaching its limits.
#wrap? ⇒ Boolean
Whether a spin button should wrap upon reaching its limits.