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> /&ast; Provides a function to retrieve an integer value from a &ast; GtkSpinButton and creates a spin button to model percentage &ast; values. &ast;/

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);

/&ast; creates the spinbutton, with no decimal places &ast;/ 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> /&ast; Provides a function to retrieve a floating point value from a &ast; GtkSpinButton, and creates a high precision spin button. &ast;/

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);

/&ast; creates the spinbutton, with three decimal places &ast;/ 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