SpinButton
open class SpinButton : Widget, SpinButtonProtocol
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_widget_show (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_widget_show (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
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.
Accessiblity
GtkSpinButton uses the GTK_ACCESSIBLE_ROLE_SPIN_BUTTON role.
The SpinButton type acts as a reference-counted owner of an underlying GtkSpinButton instance.
It provides the methods that can operate on this data type through SpinButtonProtocol conformance.
Use SpinButton as a strong reference or owner of a GtkSpinButton instance.
-
Designated initialiser from the underlying `C` data type.This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the
SpinButtoninstance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkSpinButton>)Parameters
oppointer to the underlying object
-
Designated initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theSpinButtoninstance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkSpinButton>)Parameters
oppointer to the underlying object
-
Optional initialiser from a non-mutating
gpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theSpinButtoninstance.Declaration
Swift
@inlinable override public init!(gpointer op: gpointer?)Parameters
opgpointer to the underlying object
-
Optional initialiser from a non-mutating
gconstpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theSpinButtoninstance.Declaration
Swift
@inlinable override public init!(gconstpointer op: gconstpointer?)Parameters
oppointer to the underlying object
-
Optional initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theSpinButtoninstance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkSpinButton>?)Parameters
oppointer to the underlying object
-
Optional initialiser from the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theSpinButtoninstance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkSpinButton>?)Parameters
oppointer to the underlying object
-
Designated initialiser from the underlying
Cdata type. Will retainGtkSpinButton. i.e., ownership is transferred to theSpinButtoninstance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkSpinButton>)Parameters
oppointer to the underlying object
-
Reference intialiser for a related type that implements
SpinButtonProtocolWill retainGtkSpinButton.Declaration
Swift
@inlinable public init<T>(spinButton other: T) where T : SpinButtonProtocolParameters
otheran instance of a related type that implements
SpinButtonProtocol -
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable override public init<T>(cPointer p: UnsafeMutablePointer<T>)Parameters
cPointerpointer to the underlying object
-
Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)Parameters
cPointerpointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable override public init(raw p: UnsafeRawPointer)Parameters
praw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable override public init(retainingRaw raw: UnsafeRawPointer) -
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable public required init(raw p: UnsafeMutableRawPointer)Parameters
pmutable raw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable required public init(retainingRaw raw: UnsafeMutableRawPointer)Parameters
rawmutable raw pointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable override public init(opaquePointer p: OpaquePointer)Parameters
popaque pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
SpinButtonProtocol.Declaration
Swift
@inlinable override public init(retainingOpaquePointer p: OpaquePointer)Parameters
popaque pointer to the underlying object
-
Creates a new
GtkSpinButton.Declaration
Swift
@inlinable public init<AdjustmentT>(adjustment: AdjustmentT?, climbRate: CDouble, digits: Int) where AdjustmentT : AdjustmentProtocol -
Creates a new
GtkSpinButtonwith the given properties.This is a convenience constructor that allows creation of a numeric
GtkSpinButtonwithout manually creating an adjustment. The value is initially set to the minimum value and a page increment of 10 *stepis the default. The precision of the spin button is equivalent to the precision ofstep.Note that the way in which the precision is derived works best if
stepis a power of ten. If the resulting precision is not suitable for your needs, use [methodGtk.SpinButton.set_digits] to correct it.Declaration
Swift
@inlinable public init(range min: CDouble, max: CDouble, step: CDouble) -
Creates a new
GtkSpinButtonwith the given properties.This is a convenience constructor that allows creation of a numeric
GtkSpinButtonwithout manually creating an adjustment. The value is initially set to the minimum value and a page increment of 10 *stepis the default. The precision of the spin button is equivalent to the precision ofstep.Note that the way in which the precision is derived works best if
stepis a power of ten. If the resulting precision is not suitable for your needs, use [methodGtk.SpinButton.set_digits] to correct it.Declaration
Swift
@inlinable public static func newWith(range min: CDouble, max: CDouble, step: CDouble) -> Widget!
View on GitHub
Install in Dash
SpinButton Class Reference