gtk.SpinButton



class SpinButton : gtk.Entry.Entry, gtk.OrientableIF.OrientableIF;
A #GtkSpinButton 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 #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 #GtkAdjustment section for more details about an adjustment's properties. Note that GtkSpinButton will by default make its entry large enough to accomodate the lower and upper bounds of the adjustment, which can lead to surprising results. Best practice is to set both the #GtkEntry:width-chars and #GtkEntry:max-width-chars poperties to the desired number of characters to display in the entry.

# CSS nodes

|[ spinbutton.horizontal ├── entry │ ╰── ... ├── button.down ╰── button.up ]|

|[ spinbutton.vertical ├── button.up ├── entry │ ╰── ... ╰── button.down ]|

GtkSpinButtons 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 GtkEntry subnodes (if present) are put below the entry node. The orientation of the spin button is reflected in the .vertical or .horizontal style class on the main node.

## Using a GtkSpinButton to get an integer

|[ // 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); } ]|

## Using a GtkSpinButton to get a floating point value

|[ // 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); } ]|

protected GtkSpinButton* gtkSpinButton ;
the main Gtk struct

GtkSpinButton* getSpinButtonStruct ();
Get the main Gtk struct

protected void* getStruct ();
the main Gtk struct as a void*

this(GtkSpinButton* gtkSpinButton, bool ownedRef = false);
Sets our main struct and passes it to the parent class.

static GType getType ();


this(Adjustment adjustment, double climbRate, uint digits);
Creates a new #GtkSpinButton.

Params:
Adjustment adjustment the #GtkAdjustment object that this spin button should use, or %NULL
double climbRate specifies how much the spin button changes when an arrow is clicked on
uint digits the number of decimal places to display

Return:
The new spin button as a #GtkWidget

Throws:
ConstructionException GTK+ fails to create the object.

this(double min, double max, double step);
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 gtk_spin_button_set_digits() to correct it.

Params:
double min Minimum allowable value
double max Maximum allowable value
double step Increment added or subtracted by spinning the widget

Return:
The new spin button as a #GtkWidget

Throws:
ConstructionException GTK+ fails to create the object.

void configure (Adjustment adjustment, double climbRate, uint digits);
Changes the properties of an existing spin button. The adjustment, climb rate, and number of decimal places are all changed accordingly, after this function call.

Params:
Adjustment adjustment a #GtkAdjustment
double climbRate the new climb rate
uint digits the number of decimal places to display in the spin button

Adjustment getAdjustment ();
Get the adjustment associated with a #GtkSpinButton

Return:
the #GtkAdjustment of @spin_button

uint getDigits ();
Fetches the precision of @spin_button. See gtk_spin_button_set_digits().

Return:
the current precision

void getIncrements (out double step, out double page);
Gets the current step and page the increments used by @spin_button. See gtk_spin_button_set_increments().

Params:
double step location to store step increment, or %NULL
double page location to store page increment, or %NULL

bool getNumeric ();
Returns whether non-numeric text can be typed into the spin button. See gtk_spin_button_set_numeric().

Return:
%TRUE if only numeric text can be entered

void getRange (out double min, out double max);
Gets the range allowed for @spin_button. See gtk_spin_button_set_range().

Params:
double min location to store minimum allowed value, or %NULL
double max location to store maximum allowed value, or %NULL

bool getSnapToTicks ();
Returns whether the values are corrected to the nearest step. See gtk_spin_button_set_snap_to_ticks().

Return:
%TRUE if values are snapped to the nearest step

GtkSpinButtonUpdatePolicy getUpdatePolicy ();
Gets the update behavior of a spin button. See gtk_spin_button_set_update_policy().

Return:
the current update policy

double getValue ();
Get the value in the @spin_button.

Return:
the value of @spin_button

int getValueAsInt ();
Get the value @spin_button represented as an integer.

Return:
the value of @spin_button

bool 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. See gtk_spin_button_set_wrap().

Return:
%TRUE if the spin button wraps around

void setAdjustment (Adjustment adjustment);
Replaces the #GtkAdjustment associated with @spin_button.

Params:
Adjustment adjustment a #GtkAdjustment to replace the existing adjustment

void setDigits (uint digits);
Set the precision to be displayed by @spin_button. Up to 20 digit precision is allowed.

Params:
uint digits the number of digits after the decimal point to be displayed for the spin button’s value

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.

Params:
double step increment applied for a button 1 press.
double page increment applied for a button 2 press.

void setNumeric (bool numeric);
Sets the flag that determines if non-numeric text can be typed into the spin button.

Params:
bool numeric flag indicating if only numeric entry is allowed

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.

Params:
double min minimum allowable value
double max maximum allowable value

void setSnapToTicks (bool snapToTicks);
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.

Params:
bool snapToTicks a flag indicating if invalid values should be corrected

void setUpdatePolicy (GtkSpinButtonUpdatePolicy 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.

Params:
GtkSpinButtonUpdatePolicy policy a #GtkSpinButtonUpdatePolicy value

void setValue (double value);
Sets the value of @spin_button.

Params:
double value the new value

void setWrap (bool 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.

Params:
bool wrap a flag indicating if wrapping behavior is performed

void spin (GtkSpinType direction, double increment);
Increment or decrement a spin button’s value in a specified direction by a specified amount.

Params:
GtkSpinType direction a #GtkSpinType indicating the direction to spin
double increment step increment to apply in the specified direction

void update ();
Manually force an update of the spin button.

gulong addOnChangeValue (void delegate(GtkScrollType, SpinButton) dlg, ConnectFlags connectFlags = cast(ConnectFlags)0);
The ::change-value signal is a [keybinding signal][GtkBindingSignal] which gets emitted when the user initiates a value change.

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 and/PageDown.

Params:
scroll a #GtkScrollType to specify the speed and amount of change

gulong addOnInput (int delegate(void*, SpinButton) dlg, ConnectFlags connectFlags = cast(ConnectFlags)0);
The ::input signal can be used to influence the conversion of the users input into a double value. The signal handler is expected to use gtk_entry_get_text() to retrieve the text of the entry and set @new_value to the new value.

The default conversion uses g_strtod().

Params:
newValue return location for the new value

Return:
%TRUE for a successful conversion, %FALSE if the input was not handled, and %GTK_INPUT_ERROR if the conversion failed.

gulong addOnOutput (bool delegate(SpinButton) dlg, ConnectFlags connectFlags = cast(ConnectFlags)0);
The ::output signal can be used to change to formatting of the value that is displayed in the spin buttons entry. |[ // show leading zeros static gboolean on_output (GtkSpinButton *spin, gpointer data) { GtkAdjustment *adjustment; gchar *text; int value;

adjustment = gtk_spin_button_get_adjustment (spin); value = (int)gtk_adjustment_get_value (adjustment); text = g_strdup_printf ("%02d", value); gtk_entry_set_text (GTK_ENTRY (spin), text); g_free (text);

return TRUE; } ]|

Return:
%TRUE if the value has been displayed

gulong addOnValueChanged (void delegate(SpinButton) dlg, ConnectFlags connectFlags = cast(ConnectFlags)0);
The ::value-changed signal is emitted when the value represented by @spinbutton changes. Also see the #GtkSpinButton::output signal.

gulong addOnWrapped (void delegate(SpinButton) dlg, ConnectFlags connectFlags = cast(ConnectFlags)0);
The ::wrapped signal is emitted right after the spinbutton wraps from its maximum to minimum value or vice-versa.

Since:
2.10

Page was generated with on Fri Jan 6 23:09:20 2017