Gnome::Gtk4::SpinButton
Table of Contents
Description§
A Gnome::Gtk4::SpinButton is an ideal way to allow the user to set the value of some attribute.
UNKNOWN image§
=for image :class<inline> :src<asset_files/images/spinbutton.png> :width<30\%>Rather than having to directly type a number into a Gnome::Gtk4::Entry, Gnome::Gtk4::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 Gnome::Gtk4::SpinButton are through an adjustment. See the Gnome::Gtk4::Adjustment documentation for more details about an adjustment's properties.
Note that Gnome::Gtk4::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 width-chars defined in Gnome::Gtk4::R-Editable to a value != -1.
Using a GtkSpinButton to get an integer§
Using a GtkSpinButton to get a floating point value§
CSS nodes§
Gnome::Gtk4::SpinButtons 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 Gnome::Gtk4::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§
Gnome::Gtk4::SpinButton uses the GTK_ACCESSIBLE_ROLE_SPIN_BUTTON role.
Uml Diagram§
UNKNOWN image§
=for image :class<inline> :src<asset_files/images/plantuml/SpinButton.png> :width<70\%>Class initialization§
new§
:native-object§
Create an object using a native object from an object of the same type found elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object() :$native-object! )
new-spinbutton§
Creates a new Gnome::Gtk4::SpinButton.
method new-spinbutton ( N-Object() $adjustment, Num() $climb-rate, UInt() $digits --> Gnome::Gtk4::SpinButton )
- $adjustment; the Gnome::Gtk4::Adjustment that this spin button should use.
- $climb-rate; 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.
- $digits; the number of decimal places to display.
new-with-range§
Creates a new Gnome::Gtk4::SpinButton with the given properties.
This is a convenience constructor that allows creation of a numeric Gnome::Gtk4::SpinButton 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 .set-digits() to correct it.
method new-with-range ( Num() $min, Num() $max, Num() $step --> Gnome::Gtk4::SpinButton )
- $min; Minimum allowable value.
- $max; Maximum allowable value.
- $step; Increment added or subtracted by spinning the widget.
Methods§
configure§
Changes the properties of an existing spin button.
The adjustment, climb rate, and number of decimal places are updated accordingly.
method configure ( N-Object() $adjustment, Num() $climb-rate, UInt() $digits )
- $adjustment; a Gnome::Gtk4::Adjustment to replace the spin button’s existing adjustment, or undefined to leave its current adjustment unchanged.
- $climb-rate; the new climb rate.
- $digits; the number of decimal places to display in the spin button.
get-activates-default§
Retrieves the value set by .set-activates-default().
method get-activates-default (--> Bool )
Return value; True if the spin button will activate the default widget.
get-adjustment§
Get the adjustment associated with a Gnome::Gtk4::SpinButton.
method get-adjustment (--> N-Object )
Return value; the Gnome::Gtk4::Adjustment of $spin-button.
get-climb-rate§
Returns the acceleration rate for repeated changes.
method get-climb-rate (--> Num )
Return value; the acceleration rate.
get-digits§
Fetches the precision of $spin-button.
method get-digits (--> UInt )
Return value; the current precision.
get-increments§
Gets the current step and page the increments used by $spin-button.
See .set-increments().
method get-increments ( Num() $step, Num() $page )
- $step; (transfer ownership: full) location to store step increment.
- $page; (transfer ownership: full) location to store page increment.
get-numeric§
Returns whether non-numeric text can be typed into the spin button.
method get-numeric (--> Bool )
Return value; True if only numeric text can be entered.
get-range§
Gets the range allowed for $spin-button.
See .set-range().
method get-range ( Num() $min, Num() $max )
- $min; (transfer ownership: full) location to store minimum allowed value.
- $max; (transfer ownership: full) location to store maximum allowed value.
get-snap-to-ticks§
Returns whether the values are corrected to the nearest step.
method get-snap-to-ticks (--> Bool )
Return value; True if values are snapped to the nearest step.
get-update-policy§
Gets the update behavior of a spin button.
See .set-update-policy().
method get-update-policy (--> GtkSpinButtonUpdatePolicy )
Return value; the current update policy.
get-value§
Get the value in the $spin-button.
method get-value (--> Num )
Return value; the value of $spin-button.
get-value-as-int§
Get the value $spin-button represented as an integer.
method get-value-as-int (--> Int )
Return value; the value of $spin-button.
get-wrap§
Returns whether the spin button’s value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.
method get-wrap (--> Bool )
Return value; True if the spin button wraps around.
set-activates-default§
Sets whether activating the spin button will activate the default widget for the window containing the spin button.
See activate for what counts as activation.
method set-activates-default ( Bool() $activates-default )
- $activates-default; True to activate window’s default widget on activation.
set-adjustment§
Replaces the Gnome::Gtk4::Adjustment associated with $spin-button.
method set-adjustment ( N-Object() $adjustment )
- $adjustment; a Gnome::Gtk4::Adjustment to replace the existing adjustment.
set-climb-rate§
Sets the acceleration rate for repeated changes when you hold down a button or key.
method set-climb-rate ( Num() $climb-rate )
- $climb-rate; the rate of acceleration, must be >= 0.
set-digits§
Set the precision to be displayed by $spin-button.
Up to 20 digit precision is allowed.
method set-digits ( UInt() $digits )
- $digits; the number of digits after the decimal point to be displayed for the spin button’s value.
set-increments§
Sets the step and page increments for spin_button.
This affects how quickly the value changes when the spin button’s arrows are activated.
method set-increments ( Num() $step, Num() $page )
- $step; increment applied for a button 1 press..
- $page; increment applied for a button 2 press..
set-numeric§
Sets the flag that determines if non-numeric text can be typed into the spin button.
method set-numeric ( Bool() $numeric )
- $numeric; flag indicating if only numeric entry is allowed.
set-range§
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.
method set-range ( Num() $min, Num() $max )
- $min; minimum allowable value.
- $max; maximum allowable value.
set-snap-to-ticks§
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.
method set-snap-to-ticks ( Bool() $snap-to-ticks )
- $snap-to-ticks; a flag indicating if invalid values should be corrected.
set-update-policy§
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.
method set-update-policy ( GtkSpinButtonUpdatePolicy $policy )
- $policy; a enumeration GtkSpinButtonUpdatePolicy defined in Gnome::Gtk4::T-spinbutton value.
set-value§
Sets the value of $spin-button.
method set-value ( Num() $value )
- $value; the new value.
set-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.
method set-wrap ( Bool() $wrap )
- $wrap; a flag indicating if wrapping behavior is performed.
spin§
Increment or decrement a spin button’s value in a specified direction by a specified amount.
method spin ( GtkSpinType $direction, Num() $increment )
- $direction; a enumeration GtkSpinType defined in Gnome::Gtk4::T-spinbutton indicating the direction to spin.
- $increment; step increment to apply in the specified direction.
update§
Manually force an update of the spin button.
method update ( )
Signals§
activate§
Emitted when the spin button is activated.
The keybindings for this signal are all forms of the <kbd>Enter</kbd> key.
If the <kbd>Enter</kbd> key results in the value being committed to the spin button, then activation does not occur until <kbd>Enter</kbd> is pressed again.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::SpinButton :$_widget, *%user-options )
- $_handle_id; The registered event handler id.
- $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::SpinButton object.
- %user-options; A list of named arguments provided by .register-signal() in class Object.
change-value§
Emitted when the user initiates a value change.
This is a [keybinding signal](class.SignalAction.html).
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.
method handler ( $scroll, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::SpinButton :$_widget, *%user-options )
- $scroll; a enumeration GtkScrollType defined in Gnome::Gtk4::T-enums to specify the speed and amount of change.
- $_handle_id; The registered event handler id.
- $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::SpinButton object.
- %user-options; A list of named arguments provided by .register-signal() in class Object.
input§
Emitted to convert the users input into a double value.
The signal handler is expected to use .get-text() in class Editable to retrieve the text of the spinbutton and set $new-value to the new value.
The default conversion uses g_strtod().
method handler ( gpointer $new-value, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::SpinButton :$_widget, *%user-options --> gint )
- $new-value; (transfer ownership: full)return location for the new value.
- $_handle_id; The registered event handler id.
- $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::SpinButton object.
- %user-options; A list of named arguments provided by .register-signal() in class Object.
Return value; True for a successful conversion, False if the input was not handled, and GTK_INPUT_ERROR if the conversion failed.
output§
Emitted to tweak the formatting of the value for display.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::SpinButton :$_widget, *%user-options --> gboolean )
- $_handle_id; The registered event handler id.
- $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::SpinButton object.
- %user-options; A list of named arguments provided by .register-signal() in class Object.
Return value; True if the value has been displayed
value-changed§
Emitted when the value is changed.
Also see the output signal.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::SpinButton :$_widget, *%user-options )
- $_handle_id; The registered event handler id.
- $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::SpinButton object.
- %user-options; A list of named arguments provided by .register-signal() in class Object.
wrapped§
Emitted right after the spinbutton wraps from its maximum to its minimum value or vice-versa.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::SpinButton :$_widget, *%user-options )
- $_handle_id; The registered event handler id.
- $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::SpinButton object.
- %user-options; A list of named arguments provided by .register-signal() in class Object.
About my projects, examples and tutorials