gtk.spin_button

Module for [SpinButton] class

Types 3

A [gtk.spin_button.SpinButton] is an ideal way to allow the user to set the value of some attribute.

!An example GtkSpinButton

Rather than having to directly type a number into a [gtk.entry.Entry], [gtk.spin_button.SpinButton] 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.SpinButton] are through an adjustment. See the [gtk.adjustment.Adjustment] documentation for more details about an adjustment's properties.

Note that [gtk.spin_button.SpinButton] 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 property@Gtk.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

spinbutton.horizontal
├── text
│    ├── undershoot.left
│    ╰── undershoot.right
├── button.down
╰── button.up

spinbutton.vertical
├── button.up
├── text
│    ├── undershoot.left
│    ╰── undershoot.right
╰── button.down

[gtk.spin_button.SpinButton]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 [gtk.text.Text] 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

[gtk.spin_button.SpinButton] uses the [gtk.types.AccessibleRole.SpinButton] role.

Methods
GType _gType() @property
SpinButton self()Returns `this`, for use in `with` statements.
SpinButtonGidBuilder builder()Get builder for [gtk.spin_button.SpinButton] Returns: New builder object
bool activatesDefault() @propertyGet `activatesDefault` property. Returns: Whether to activate the default widget when the spin button is activated.
void activatesDefault(bool propval) @propertySet `activatesDefault` property. Params: propval = Whether to activate the default widget when the spin button is activated.
gtk.adjustment.Adjustment adjustment() @propertyGet `adjustment` property. Returns: The adjustment that holds the value of the spin button.
void adjustment(gtk.adjustment.Adjustment propval) @propertySet `adjustment` property. Params: propval = The adjustment that holds the value of the spin button.
double climbRate() @propertyGet `climbRate` property. Returns: The acceleration rate when you hold down a button or key.
void climbRate(double propval) @propertySet `climbRate` property. Params: propval = The acceleration rate when you hold down a button or key.
uint digits() @propertyGet `digits` property. Returns: The number of decimal places to display.
void digits(uint propval) @propertySet `digits` property. Params: propval = The number of decimal places to display.
bool numeric() @propertyGet `numeric` property. Returns: Whether non-numeric characters should be ignored.
void numeric(bool propval) @propertySet `numeric` property. Params: propval = Whether non-numeric characters should be ignored.
bool snapToTicks() @propertyGet `snapToTicks` property. Returns: Whether erroneous values are automatically changed to the spin buttons nearest step increment.
void snapToTicks(bool propval) @propertySet `snapToTicks` property. Params: propval = Whether erroneous values are automatically changed to the spin buttons nearest step increment.
gtk.types.SpinButtonUpdatePolicy updatePolicy() @propertyGet `updatePolicy` property. Returns: Whether the spin button should update always, or only when the value is acceptable.
void updatePolicy(gtk.types.SpinButtonUpdatePolicy propval) @propertySet `updatePolicy` property. Params: propval = Whether the spin button should update always, or only when the value is acceptable.
double value() @propertyGet `value` property. Returns: The current value.
void value(double propval) @propertySet `value` property. Params: propval = The current value.
bool wrap() @propertyGet `wrap` property. Returns: Whether a spin button should wrap upon reaching its limits.
void wrap(bool propval) @propertySet `wrap` property. Params: propval = Whether a spin button should wrap upon reaching its limits.
gtk.spin_button.SpinButton newWithRange(double min, double max, double step)Creates a new [gtk.spin_button.SpinButton] with the given properties.
void configure(gtk.adjustment.Adjustment adjustment, double climbRate, uint digits)Changes the properties of an existing spin button.
bool getActivatesDefault()Retrieves the value set by [gtk.spin_button.SpinButton.setActivatesDefault]. Returns: true if the spin button will activate the default widget
gtk.adjustment.Adjustment getAdjustment()Get the adjustment associated with a [gtk.spinbutton.SpinButton]. Returns: the [gtk.adjustment.Adjustment] of spinbutton
double getClimbRate()Returns the acceleration rate for repeated changes. Returns: the acceleration rate
uint getDigits()Fetches the precision of spin_button. Returns: the current precision
void getIncrements(out double step, out double page)Gets the current step and page the increments used by spin_button.
bool getNumeric()Returns whether non-numeric text can be typed into the spin button. Returns: true if only numeric text can be entered
void getRange(out double min, out double max)Gets the range allowed for spin_button.
bool getSnapToTicks()Returns whether the values are corrected to the nearest step. Returns: true if values are snapped to the nearest step
gtk.types.SpinButtonUpdatePolicy getUpdatePolicy()Gets the update behavior of a spin button.
double getValue()Get the value in the spinbutton. Returns: the value of spinbutton
int getValueAsInt()Get the value spinbutton represented as an integer. Returns: the value of spinbutton
bool getWrap()Returns whether the spin button’s value wraps around to the opposite limit when the upper or lower limit of the range is exceeded. Returns: true if the spin button wraps around
void setActivatesDefault(bool activatesDefault)Sets whether activating the spin button will activate the default widget for the window containing the spin button.
void setAdjustment(gtk.adjustment.Adjustment adjustment)Replaces the [gtk.adjustment.Adjustment] associated with spin_button.
void setClimbRate(double climbRate)Sets the acceleration rate for repeated changes when you hold down a button or key.
void setDigits(uint digits)Set the precision to be displayed by spin_button.
void setIncrements(double step, double page)Sets the step and page increments for spin_button.
void setNumeric(bool numeric)Sets the flag that determines if non-numeric text can be typed into the spin button.
void setRange(double min, double max)Sets the minimum and maximum allowable values for spin_button.
void setSnapToTicks(bool snapToTicks)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.
void setUpdatePolicy(gtk.types.SpinButtonUpdatePolicy policy)Sets the update behavior of a spin button.
void setValue(double value)Sets the value of spin_button.
void setWrap(bool wrap)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.
void spin(gtk.types.SpinType direction, double increment)Increment or decrement a spin button’s value in a specified direction by a specified amount.
void update()Manually force an update of the spin button.
gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.spin_button.SpinButton))) && Parameters!T.length < 2)Connect to `Activate` signal.
gulong connectChangeValue(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.ScrollType))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.spin_button.SpinButton))) && Parameters!T.length < 3)Connect to `ChangeValue` signal.
gulong connectInput(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == int) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.out_ && is(Parameters!T[0] == double))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.spin_button.SpinButton))) && Parameters!T.length < 3)Connect to `Input` signal.
gulong connectOutput(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == bool) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.spin_button.SpinButton))) && Parameters!T.length < 2)Connect to `Output` signal.
gulong connectValueChanged(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.spin_button.SpinButton))) && Parameters!T.length < 2)Connect to `ValueChanged` signal.
gulong connectWrapped(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.spin_button.SpinButton))) && Parameters!T.length < 2)Connect to `Wrapped` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this(gtk.adjustment.Adjustment adjustment, double climbRate, uint digits)Creates a new [gtk.spin_button.SpinButton].
Methods
T activatesDefault(bool propval)Set `activatesDefault` property. Params: propval = Whether to activate the default widget when the spin button is activated.
T adjustment(gtk.adjustment.Adjustment propval)Set `adjustment` property. Params: propval = The adjustment that holds the value of the spin button. Returns: Builder instance for fluent chaining
T climbRate(double propval)Set `climbRate` property. Params: propval = The acceleration rate when you hold down a button or key. Returns: Builder instance for fluent chaining
T digits(uint propval)Set `digits` property. Params: propval = The number of decimal places to display. Returns: Builder instance for fluent chaining
T numeric(bool propval)Set `numeric` property. Params: propval = Whether non-numeric characters should be ignored. Returns: Builder instance for fluent chaining
T snapToTicks(bool propval)Set `snapToTicks` property. Params: propval = Whether erroneous values are automatically changed to the spin buttons nearest step increment. Returns: Builder instance for fluent chaining
T updatePolicy(gtk.types.SpinButtonUpdatePolicy propval)Set `updatePolicy` property. Params: propval = Whether the spin button should update always, or only when the value is acceptable. Returns: Builder instance for fluent chaining
T value(double propval)Set `value` property. Params: propval = The current value. Returns: Builder instance for fluent chaining
T wrap(bool propval)Set `wrap` property. Params: propval = Whether a spin button should wrap upon reaching its limits. Returns: Builder instance for fluent chaining

Fluent builder for [gtk.spin_button.SpinButton]

Methods
SpinButton build()