Struct gtk4::SpinButton [−][src]
pub struct SpinButton(_);
Expand description
A SpinButton
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 Entry
,
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 SpinButton
are through an adjustment.
See the Adjustment
documentation for more details about
an adjustment’s properties.
Note that 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::Editable::width-chars
to a value != -1.
Using a GtkSpinButton to get an integer
⚠️ The following code is in 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
⚠️ The following code is in 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
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 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.
Accessiblity
SpinButton
uses the AccessibleRole::SpinButton
role.
Implements
WidgetExt
, glib::ObjectExt
, AccessibleExt
, BuildableExt
, ConstraintTargetExt
, CellEditableExt
, EditableExt
, OrientableExt
, WidgetExtManual
, AccessibleExtManual
, CellEditableExtManual
, EditableExtManual
Implementations
pub fn new<P: IsA<Adjustment>>(
adjustment: Option<&P>,
climb_rate: f64,
digits: u32
) -> SpinButton
pub fn new<P: IsA<Adjustment>>(
adjustment: Option<&P>,
climb_rate: f64,
digits: u32
) -> SpinButton
Creates a new SpinButton
.
adjustment
the 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
Returns
The new SpinButton
Creates a new SpinButton
with the given properties.
This is a convenience constructor that allows creation
of a numeric 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.
min
Minimum allowable value
max
Maximum allowable value
step
Increment added or subtracted by spinning the widget
Returns
The new SpinButton
Creates a new builder-pattern struct instance to construct SpinButton
objects.
This method returns an instance of SpinButtonBuilder
which can be used to create SpinButton
objects.
Changes the properties of an existing spin button.
The adjustment, climb rate, and number of decimal places are updated accordingly.
adjustment
a Adjustment
to replace the spin button’s
existing adjustment, or None
to leave its current adjustment unchanged
climb_rate
the new climb rate
digits
the number of decimal places to display in the spin button
Gets the current step and page the increments
used by self
.
See set_increments()
.
Returns
step
location to store step increment
page
location to store page increment
Gets the range allowed for self
.
See set_range()
.
Returns
min
location to store minimum allowed value
max
location to store maximum allowed value
Gets the update behavior of a spin button.
See set_update_policy()
.
Returns
the current update policy
Replaces the Adjustment
associated with self
.
adjustment
a Adjustment
to replace the existing adjustment
Sets the acceleration rate for repeated changes when you hold down a button or key.
climb_rate
the rate of acceleration, must be >= 0
Set the precision to be displayed by self
.
Up to 20 digit precision is allowed.
digits
the number of digits after the decimal point to be displayed for the spin button’s value
Sets the flag that determines if non-numeric text can be typed into the spin button.
numeric
flag indicating if only numeric entry is allowed
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.
snap_to_ticks
a flag indicating if invalid values should be corrected
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.
policy
a SpinButtonUpdatePolicy
value
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.
wrap
a flag indicating if wrapping behavior is performed
pub fn connect_change_value<F: Fn(&Self, ScrollType) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_change_value<F: Fn(&Self, ScrollType) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when the user initiates a value change.
This is a keybinding signal.
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.
scroll
a ScrollType
to specify the speed and amount of change
Emitted to tweak the formatting of the value for display.
⚠️ The following code is in c ⚠️
// show leading zeros
static gboolean
on_output (GtkSpinButton *spin,
gpointer data)
{
GtkAdjustment *adjustment;
char *text;
int value;
adjustment = gtk_spin_button_get_adjustment (spin);
value = (int)gtk_adjustment_get_value (adjustment);
text = g_strdup_printf ("%02d", value);
gtk_spin_button_set_text (spin, text):
g_free (text);
return TRUE;
}
Returns
true
if the value has been displayed
Emitted when the value is changed.
Also see the signal::SpinButton::output
signal.
Emitted right after the spinbutton wraps from its maximum to its minimum value or vice-versa.
pub fn connect_input<F>(&self, f: F) -> SignalHandlerId where
F: Fn(&Self) -> Option<Result<f64, ()>> + 'static,
pub fn connect_input<F>(&self, f: F) -> SignalHandlerId where
F: Fn(&Self) -> Option<Result<f64, ()>> + 'static,
Emitted to convert the users input into a double value.
The signal handler is expected to use EditableExt::text()
to retrieve the text of the spinbutton and set new_value
to the
new value.
The default conversion uses g_strtod()
.
Returns
true
for a successful conversion, false
if the input
was not handled, and GTK_INPUT_ERROR
if the conversion failed.
new_value
return location for the new value
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for SpinButton
impl !Send for SpinButton
impl !Sync for SpinButton
impl Unpin for SpinButton
impl UnwindSafe for SpinButton
Blanket Implementations
Mutably borrows from an owned value. Read more
Upcasts an object to a superclass or interface T
. Read more
Upcasts an object to a reference of its superclass or interface T
. Read more
Tries to downcast to a subclass or interface implementor T
. Read more
Tries to downcast to a reference of its subclass or interface implementor T
. Read more
Tries to cast to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Tries to cast to reference to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Casts to T
unconditionally. Read more
Casts to &T
unconditionally. Read more
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
N: Into<&'a str>,
V: ToValue,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: Fn(&[Value]) -> Option<Value>,
Same as connect_unsafe
but takes a SignalId
instead of a signal name.
Emit signal by signal id.
Same as emit
but takes Value
for the arguments.
Emit signal by its name.
Same as emit_by_name
but takes Value
for the arguments.
Emit signal with details by signal id.
Same as emit_with_details
but takes Value
for the arguments.
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Returns a SendValue
clone of self
.