Gtk.SpinButton
const Gtk = imports.gi.Gtk; let spin_button = new Gtk.SpinButton({ adjustment: value, climb_rate: value, digits: value, numeric: value, snap_to_ticks: value, update_policy: value, value: value, wrap: value, });
A Gtk.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 Gtk.Entry, 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 Gtk.Adjustment section for more details about an adjustment's properties.
<example> <title>Using a GtkSpinButton to get an integer</title> <programlisting> /* 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); } </programlisting> </example>
<example> <title>Using a GtkSpinButton to get a floating point value</title> <programlisting> /* 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); } </programlisting> </example>
Hierarchy
-
GObject.Object
-
GObject.InitiallyUnowned
-
Gtk.Widget
-
Gtk.Entry
- Gtk.SpinButton
-
-
-
Methods
- Gtk.SpinButton.prototype.configure
- Gtk.SpinButton.prototype.get_adjustment
- Gtk.SpinButton.prototype.get_digits
- Gtk.SpinButton.prototype.get_increments
- Gtk.SpinButton.prototype.get_numeric
- Gtk.SpinButton.prototype.get_range
- Gtk.SpinButton.prototype.get_snap_to_ticks
- Gtk.SpinButton.prototype.get_update_policy
- Gtk.SpinButton.prototype.get_value
- Gtk.SpinButton.prototype.get_value_as_int
- Gtk.SpinButton.prototype.get_wrap
- Gtk.SpinButton.prototype.set_adjustment
- Gtk.SpinButton.prototype.set_digits
- Gtk.SpinButton.prototype.set_increments
- Gtk.SpinButton.prototype.set_numeric
- Gtk.SpinButton.prototype.set_range
- Gtk.SpinButton.prototype.set_snap_to_ticks
- Gtk.SpinButton.prototype.set_update_policy
- Gtk.SpinButton.prototype.set_value
- Gtk.SpinButton.prototype.set_wrap
- Gtk.SpinButton.prototype.spin
- Gtk.SpinButton.prototype.update