gtk.spin_button
Module for [SpinButton] class
Types 3
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 #GtkAdjustment section for more details about an adjustment's properties. Note that GtkSpinButton will by default make its entry large enough to accomodate the lower and upper bounds of the adjustment, which can lead to surprising results. Best practice is to set both the #GtkEntry:width-chars and #GtkEntry:max-width-chars poperties to the desired number of characters to display in the entry.
CSS nodes
spinbutton.horizontal
├── undershoot.left
├── undershoot.right
├── entry
│ ╰── ...
├── button.down
╰── button.up spinbutton.vertical
├── undershoot.left
├── undershoot.right
├── button.up
├── entry
│ ╰── ...
╰── button.downGtkSpinButtons 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 GtkEntry subnodes (if present) are put below the entry node. The orientation of the spin button is reflected in the .vertical or .horizontal style class on the main node.
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.
gint
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 (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
// creates the spinbutton, with no decimal places
button = gtk_spin_button_new (adjustment, 1.0, 0);
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show_all (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.
gfloat
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 (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
// creates the spinbutton, with three decimal places
button = gtk_spin_button_new (adjustment, 0.001, 3);
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show_all (window);
}SpinButtonGidBuilder builder() static nothrowGet builder for [gtk.spin_button.SpinButton] Returns: New builder objectgtk.spin_button.SpinButton newWithRange(double min, double max, double step) static nothrowThis 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 1...void configure(gtk.adjustment.Adjustment adjustment, double climbRate, uint digits) nothrowChanges the properties of an existing spin button. The adjustment, climb rate, and number of decimal places are updated accordingly.gtk.adjustment.Adjustment getAdjustment() nothrowGet the adjustment associated with a #GtkSpinButton Returns: the #GtkAdjustment of spin_buttonuint getDigits() nothrowFetches the precision of spin_button. See [gtk.spin_button.SpinButton.setDigits]. Returns: the current precisionvoid getIncrements(out double step, out double page) nothrowGets the current step and page the increments used by spin_button. See [gtk.spin_button.SpinButton.setIncrements].bool getNumeric() nothrowReturns whether non-numeric text can be typed into the spin button. See [gtk.spin_button.SpinButton.setNumeric]. Returns: true if only numeric text can be enteredvoid getRange(out double min, out double max) nothrowGets the range allowed for spin_button. See [gtk.spin_button.SpinButton.setRange].bool getSnapToTicks() nothrowReturns whether the values are corrected to the nearest step. See [gtk.spin_button.SpinButton.setSnapToTicks]. Returns: true if values are snapped to the nearest stepgtk.types.SpinButtonUpdatePolicy getUpdatePolicy() nothrowGets the update behavior of a spin button. See [gtk.spin_button.SpinButton.setUpdatePolicy]. Returns: the current update policyint getValueAsInt() nothrowGet the value spin_button represented as an integer. Returns: the value of spin_buttonbool getWrap() nothrowReturns 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.SpinButton.setWrap]. Returns: true if the s...void setAdjustment(gtk.adjustment.Adjustment adjustment) nothrowReplaces the #GtkAdjustment associated with spin_button.void setDigits(uint digits) nothrowSet the precision to be displayed by spin_button. Up to 20 digit precision is allowed.void setIncrements(double step, double page) nothrowSets the step and page increments for spin_button. This affects how quickly the value changes when the spin button’s arrows are activated.void setNumeric(bool numeric) nothrowSets the flag that determines if non-numeric text can be typed into the spin button.void setRange(double min, double max) nothrowSets the minimum and maximum allowable values for spin_button.void setSnapToTicks(bool snapToTicks) nothrowSets 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) nothrowSets the update behavior of a spin button. This determines whether the spin button is always updated or only when a valid value is set.void setWrap(bool wrap) nothrowSets 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) nothrowIncrement or decrement a spin button’s value in a specified direction by a specified amount.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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect to `Wrapped` signal.this(gtk.adjustment.Adjustment adjustment, double climbRate, uint digits)Creates a new #GtkSpinButton.Fluent builder implementation template for gtk.spin_button.SpinButton
T adjustment(gtk.adjustment.Adjustment propval) nothrowT climbRate(double propval) nothrowT digits(uint propval) nothrowT numeric(bool propval) nothrowT snapToTicks(bool propval) nothrowT updatePolicy(gtk.types.SpinButtonUpdatePolicy propval) nothrowT value(double propval) nothrowT wrap(bool propval) nothrowFluent builder for gtk.spin_button.SpinButton