Package ch.bailu.gtk.gtk
Class SpinButton
- All Implemented Interfaces:
PointerInterface
A `GtkSpinButton` is an ideal way to allow the user to set the
value of some attribute.
![An example GtkSpinButton](spinbutton.png)
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 [class@Gtk.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 [property@Gtk.Editable:width-chars] to a value != -1.
## Using a GtkSpinButton to get an integer
```c
// 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
```c
// 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
```
`GtkSpinButton`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 `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.
value of some attribute.
![An example GtkSpinButton](spinbutton.png)
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 [class@Gtk.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 [property@Gtk.Editable:width-chars] to a value != -1.
## Using a GtkSpinButton to get an integer
```c
// 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
```c
// 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
```
`GtkSpinButton`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 `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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionSpinButton
(Adjustment adjustment, double climb_rate, int digits) Creates a new `GtkSpinButton`.SpinButton
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceCellEditable
.Implements interfaceConstraintTarget
.Implements interfaceEditable
.Implements interfaceOrientable
.void
configure
(Adjustment adjustment, double climb_rate, int digits) Changes the properties of an existing spin button.Get the adjustment associated with a `GtkSpinButton`.static ClassHandler
double
Returns the acceleration rate for repeated changes.int
Fetches the precision of @spin_button.static int
boolean
Returns whether non-numeric text can be typed into the spin button.static long
static TypeSystem.TypeSize
boolean
Returns whether the values are corrected to the nearest step.static long
static TypeSystem.TypeSize
int
Gets the update behavior of a spin button.double
getValue()
Get the value in the @spin_button.int
Get the value @spin_button represented as an integer.boolean
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.static SpinButton
newWithRangeSpinButton
(double min, double max, double step) Creates a new `GtkSpinButton` with the given properties.Connect to signal "change-value".onInput
(SpinButton.OnInput signal) Connect to signal "input".onOutput
(SpinButton.OnOutput signal) Connect to signal "output".Connect to signal "value-changed".onWrapped
(SpinButton.OnWrapped signal) Connect to signal "wrapped".void
setAdjustment
(Adjustment adjustment) Replaces the `GtkAdjustment` associated with @spin_button.void
setClimbRate
(double climb_rate) Sets the acceleration rate for repeated changes when you
hold down a button or key.void
setDigits
(int 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
(boolean 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
(boolean 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.void
setUpdatePolicy
(int policy) Sets the update behavior of a spin button.void
setValue
(double value) Sets the value of @spin_button.void
setWrap
(boolean 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
(int 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.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_CHANGE_VALUE
- See Also:
-
SIGNAL_ON_INPUT
- See Also:
-
SIGNAL_ON_OUTPUT
- See Also:
-
SIGNAL_ON_VALUE_CHANGED
- See Also:
-
SIGNAL_ON_WRAPPED
- See Also:
-
-
Constructor Details
-
SpinButton
-
SpinButton
Creates a new `GtkSpinButton`.- Parameters:
adjustment
- the `GtkAdjustment` that this spin button should useclimb_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 keydigits
- the number of decimal places to display
-
-
Method Details
-
getClassHandler
-
newWithRangeSpinButton
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
[method@Gtk.SpinButton.set_digits] to correct it.- Parameters:
min
- Minimum allowable valuemax
- Maximum allowable valuestep
- Increment added or subtracted by spinning the widget- Returns:
- The new `GtkSpinButton`
-
configure
Changes the properties of an existing spin button.
The adjustment, climb rate, and number of decimal places
are updated accordingly.- Parameters:
adjustment
- a `GtkAdjustment` to replace the spin button’s existing adjustment, or %NULL to leave its current adjustment unchangedclimb_rate
- the new climb ratedigits
- the number of decimal places to display in the spin button
-
getAdjustment
Get the adjustment associated with a `GtkSpinButton`.- Returns:
- the `GtkAdjustment` of @spin_button
-
getClimbRate
public double getClimbRate()Returns the acceleration rate for repeated changes.- Returns:
- the acceleration rate
-
getDigits
public int getDigits()Fetches the precision of @spin_button.- Returns:
- the current precision
-
getNumeric
public boolean getNumeric()Returns whether non-numeric text can be typed into the spin button.- Returns:
- %TRUE if only numeric text can be entered
-
getSnapToTicks
public boolean getSnapToTicks()Returns whether the values are corrected to the nearest step.- Returns:
- %TRUE if values are snapped to the nearest step
-
getUpdatePolicy
public int getUpdatePolicy()Gets the update behavior of a spin button.
See [method@Gtk.SpinButton.set_update_policy].- Returns:
- the current update policy
-
getValue
public double getValue()Get the value in the @spin_button.- Returns:
- the value of @spin_button
-
getValueAsInt
public int getValueAsInt()Get the value @spin_button represented as an integer.- Returns:
- the value of @spin_button
-
getWrap
public boolean 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
-
setAdjustment
Replaces the `GtkAdjustment` associated with @spin_button.- Parameters:
adjustment
- a `GtkAdjustment` to replace the existing adjustment
-
setClimbRate
public void setClimbRate(double climb_rate) Sets the acceleration rate for repeated changes when you
hold down a button or key.- Parameters:
climb_rate
- the rate of acceleration, must be >= 0
-
setDigits
public void setDigits(int digits) Set the precision to be displayed by @spin_button.
Up to 20 digit precision is allowed.- Parameters:
digits
- the number of digits after the decimal point to be displayed for the spin button’s value
-
setIncrements
public void setIncrements(double step, double page) Sets the step and page increments for spin_button.
This affects how quickly the value changes when
the spin button’s arrows are activated.- Parameters:
step
- increment applied for a button 1 press.page
- increment applied for a button 2 press.
-
setNumeric
public void setNumeric(boolean numeric) Sets the flag that determines if non-numeric text can be typed
into the spin button.- Parameters:
numeric
- flag indicating if only numeric entry is allowed
-
setRange
public void setRange(double min, double max) 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.- Parameters:
min
- minimum allowable valuemax
- maximum allowable value
-
setSnapToTicks
public void setSnapToTicks(boolean 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.- Parameters:
snap_to_ticks
- a flag indicating if invalid values should be corrected
-
setUpdatePolicy
public void setUpdatePolicy(int 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.- Parameters:
policy
- a `GtkSpinButtonUpdatePolicy` value
-
setValue
public void setValue(double value) Sets the value of @spin_button.- Parameters:
value
- the new value
-
setWrap
public void setWrap(boolean 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.- Parameters:
wrap
- a flag indicating if wrapping behavior is performed
-
spin
public void spin(int direction, double increment) Increment or decrement a spin button’s value in a specified
direction by a specified amount.- Parameters:
direction
- a `GtkSpinType` indicating the direction to spinincrement
- step increment to apply in the specified direction
-
update
public void update()Manually force an update of the spin button. -
onChangeValue
Connect to signal "change-value".
SeeSpinButton.OnChangeValue.onChangeValue(int)
for signal description.
FieldSIGNAL_ON_CHANGE_VALUE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onInput
Connect to signal "input".
SeeSpinButton.OnInput.onInput(ch.bailu.gtk.type.Pointer)
for signal description.
FieldSIGNAL_ON_INPUT
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onOutput
Connect to signal "output".
SeeSpinButton.OnOutput.onOutput()
for signal description.
FieldSIGNAL_ON_OUTPUT
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onValueChanged
Connect to signal "value-changed".
SeeSpinButton.OnValueChanged.onValueChanged()
for signal description.
FieldSIGNAL_ON_VALUE_CHANGED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onWrapped
Connect to signal "wrapped".
SeeSpinButton.OnWrapped.onWrapped()
for signal description.
FieldSIGNAL_ON_WRAPPED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asCellEditable
Implements interfaceCellEditable
. Call this to get access to interface functions.- Returns:
CellEditable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
asEditable
Implements interfaceEditable
. Call this to get access to interface functions.- Returns:
Editable
-
asOrientable
Implements interfaceOrientable
. Call this to get access to interface functions.- Returns:
Orientable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-