SpinButton

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. 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 width-chars and max-width-chars poperties to the desired number of characters to display in the entry.

CSS nodes

|[<!-- language="plain" --> spinbutton.horizontal ├── undershoot.left ├── undershoot.right ├── entry │ ╰── ... ├── button.down ╰── button.up

|[<!-- language="plain" -->
spinbutton.vertical
├── undershoot.left
├── undershoot.right
├── 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);
}

Constructors

this
this(GtkSpinButton* gtkSpinButton, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(Adjustment adjustment, double climbRate, uint digits)

Creates a new gtk.SpinButton

this
this(double min, double max, double step)

This is a convenience constructor that allows creation of a numeric gtk.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.

Members

Functions

addOnChangeValue
gulong addOnChangeValue(void delegate(GtkScrollType, SpinButton) dlg, ConnectFlags connectFlags)

The ::change-value signal is a [keybinding signal]GtkBindingSignal which gets emitted when the user initiates a value change.

addOnInput
gulong addOnInput(int delegate(void*, SpinButton) dlg, ConnectFlags connectFlags)

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 Entry.getText to retrieve the text of the entry and set new_value to the new value.

addOnOutput
gulong addOnOutput(bool delegate(SpinButton) dlg, ConnectFlags connectFlags)

The ::output signal can be used to change to formatting of the value that is displayed in the spin buttons entry.

addOnValueChanged
gulong addOnValueChanged(void delegate(SpinButton) dlg, ConnectFlags connectFlags)

The ::value-changed signal is emitted when the value represented by spinbutton changes. Also see the output signal.

addOnWrapped
gulong addOnWrapped(void delegate(SpinButton) dlg, ConnectFlags connectFlags)

The ::wrapped signal is emitted right after the spinbutton wraps from its maximum to minimum value or vice-versa.

configure
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 updated accordingly.

getAdjustment
Adjustment getAdjustment()

Get the adjustment associated with a gtk.SpinButton

getDigits
uint getDigits()

Fetches the precision of spin_button. See SpinButton.setDigits.

getIncrements
void getIncrements(double step, double page)

Gets the current step and page the increments used by spin_button. See SpinButton.setIncrements.

getNumeric
bool getNumeric()

Returns whether non-numeric text can be typed into the spin button. See SpinButton.setNumeric.

getRange
void getRange(double min, double max)

Gets the range allowed for spin_button. See SpinButton.setRange.

getSnapToTicks
bool getSnapToTicks()

Returns whether the values are corrected to the nearest step. See SpinButton.setSnapToTicks.

getSpinButtonStruct
GtkSpinButton* getSpinButtonStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getUpdatePolicy
GtkSpinButtonUpdatePolicy getUpdatePolicy()

Gets the update behavior of a spin button. See SpinButton.setUpdatePolicy.

getValue
double getValue()

Get the value in the spin_button.

getValueAsInt
int getValueAsInt()

Get the value spin_button represented as an integer.

getWrap
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 SpinButton.setWrap.

setAdjustment
void setAdjustment(Adjustment adjustment)

Replaces the gtk.Adjustment associated with spin_button.

setDigits
void setDigits(uint digits)

Set the precision to be displayed by spin_button. Up to 20 digit precision is allowed.

setIncrements
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.

setNumeric
void setNumeric(bool numeric)

Sets the flag that determines if non-numeric text can be typed into the spin button.

setRange
void setRange(double min, double max)

Sets the minimum and maximum allowable values for spin_button.

setSnapToTicks
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.

setUpdatePolicy
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.

setValue
void setValue(double value)

Sets the value of spin_button.

setWrap
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.

spin
void spin(GtkSpinType direction, double increment)

Increment or decrement a spin button’s value in a specified direction by a specified amount.

update
void update()

Manually force an update of the spin button.

Static functions

getType
GType getType()

Variables

gtkSpinButton
GtkSpinButton* gtkSpinButton;

the main Gtk struct

Inherited Members

From Entry

gtkEntry
GtkEntry* gtkEntry;

the main Gtk struct

getEntryStruct
GtkEntry* getEntryStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getStockId
StockID getStockId(GtkEntryIconPosition iconPos)

Gets the stock id of action. Since 2.16

setStockId
void setStockId(GtkEntryIconPosition iconPos, StockID stockId)

Sets the stock id on action Since 2.16

getType
GType getType()
getActivatesDefault
bool getActivatesDefault()

Retrieves the value set by Entry.setActivatesDefault.

getAlignment
float getAlignment()

Gets the value set by Entry.setAlignment.

getAttributes
PgAttributeList getAttributes()

Gets the attribute list that was set on the entry using Entry.setAttributes, if any.

getBuffer
EntryBuffer getBuffer()

Get the gtk.EntryBuffer object which holds the text for this widget.

getCompletion
EntryCompletion getCompletion()

Returns the auxiliary completion object currently in use by entry.

getCurrentIconDragSource
int getCurrentIconDragSource()

Returns the index of the icon which is the source of the current DND operation, or -1.

getCursorHadjustment
Adjustment getCursorHadjustment()

Retrieves the horizontal cursor adjustment for the entry. See Entry.setCursorHadjustment.

getHasFrame
bool getHasFrame()

Gets the value set by Entry.setHasFrame.

getIconActivatable
bool getIconActivatable(GtkEntryIconPosition iconPos)

Returns whether the icon is activatable.

getIconArea
void getIconArea(GtkEntryIconPosition iconPos, GdkRectangle iconArea)

Gets the area where entry’s icon at icon_pos is drawn. This function is useful when drawing something to the entry in a draw callback.

getIconAtPos
int getIconAtPos(int x, int y)

Finds the icon at the given position and return its index. The position’s coordinates are relative to the entry’s top left corner. If x, y doesn’t lie inside an icon, -1 is returned. This function is intended for use in a query-tooltip signal handler.

getIconGicon
IconIF getIconGicon(GtkEntryIconPosition iconPos)

Retrieves the GIcon used for the icon, or NULL if there is no icon or if the icon was set by some other method (e.g., by stock, pixbuf, or icon name).

getIconName
string getIconName(GtkEntryIconPosition iconPos)

Retrieves the icon name used for the icon, or NULL if there is no icon or if the icon was set by some other method (e.g., by pixbuf, stock or gicon).

getIconPixbuf
Pixbuf getIconPixbuf(GtkEntryIconPosition iconPos)

Retrieves the image used for the icon.

getIconSensitive
bool getIconSensitive(GtkEntryIconPosition iconPos)

Returns whether the icon appears sensitive or insensitive.

getIconStock
string getIconStock(GtkEntryIconPosition iconPos)

Retrieves the stock id used for the icon, or NULL if there is no icon or if the icon was set by some other method (e.g., by pixbuf, icon name or gicon).

getIconStorageType
GtkImageType getIconStorageType(GtkEntryIconPosition iconPos)

Gets the type of representation being used by the icon to store image data. If the icon has no image data, the return value will be GTK_IMAGE_EMPTY.

getIconTooltipMarkup
string getIconTooltipMarkup(GtkEntryIconPosition iconPos)

Gets the contents of the tooltip on the icon at the specified position in entry.

getIconTooltipText
string getIconTooltipText(GtkEntryIconPosition iconPos)

Gets the contents of the tooltip on the icon at the specified position in entry.

getInnerBorder
Border getInnerBorder()

This function returns the entry’s inner-border property. See Entry.setInnerBorder for more information.

getInputHints
GtkInputHints getInputHints()

Gets the value of the input-hints property.

getInputPurpose
GtkInputPurpose getInputPurpose()

Gets the value of the input-purpose property.

getInvisibleChar
dchar getInvisibleChar()

Retrieves the character displayed in place of the real characters for entries with visibility set to false. See Entry.setInvisibleChar.

getLayout
PgLayout getLayout()

Gets the gtk.Layout used to display the entry. The layout is useful to e.g. convert text positions to pixel positions, in combination with Entry.getLayoutOffsets. The returned layout is owned by the entry and must not be modified or freed by the caller.

getLayoutOffsets
void getLayoutOffsets(int x, int y)

Obtains the position of the gtk.Layout used to render text in the entry, in widget coordinates. Useful if you want to line up the text in an entry with some other text, e.g. when using the entry to implement editable cells in a sheet widget.

getMaxLength
int getMaxLength()

Retrieves the maximum allowed length of the text in entry. See Entry.setMaxLength.

getMaxWidthChars
int getMaxWidthChars()

Retrieves the desired maximum width of entry, in characters. See Entry.setMaxWidthChars.

getOverwriteMode
bool getOverwriteMode()

Gets the value set by Entry.setOverwriteMode.

getPlaceholderText
string getPlaceholderText()

Retrieves the text that will be displayed when entry is empty and unfocused

getProgressFraction
double getProgressFraction()

Returns the current fraction of the task that’s been completed. See Entry.setProgressFraction.

getProgressPulseStep
double getProgressPulseStep()

Retrieves the pulse step set with Entry.setProgressPulseStep.

getTabs
PgTabArray getTabs()

Gets the tabstops that were set on the entry using Entry.setTabs, if any.

getText
string getText()

Retrieves the contents of the entry widget. See also gtk_editable_get_chars().

getTextArea
void getTextArea(GdkRectangle textArea)

Gets the area where the entry’s text is drawn. This function is useful when drawing something to the entry in a draw callback.

getTextLength
ushort getTextLength()

Retrieves the current length of the text in entry.

getVisibility
bool getVisibility()

Retrieves whether the text in entry is visible. See Entry.setVisibility.

getWidthChars
int getWidthChars()

Gets the value set by Entry.setWidthChars.

grabFocusWithoutSelecting
void grabFocusWithoutSelecting()

Causes entry to have keyboard focus.

imContextFilterKeypress
bool imContextFilterKeypress(GdkEventKey* event)

Allow the gtk.Entry input method to internally handle key press and release events. If this function returns TRUE, then no further processing should be done for this key event. See gtk_im_context_filter_keypress().

layoutIndexToTextIndex
int layoutIndexToTextIndex(int layoutIndex)

Converts from a position in the entry’s gtk.Layout (returned by Entry.getLayout) to a position in the entry contents (returned by Entry.getText).

progressPulse
void progressPulse()

Indicates that some progress is made, but you don’t know how much. Causes the entry’s progress indicator to enter “activity mode,” where a block bounces back and forth. Each call to Entry.progressPulse causes the block to move by a little bit (the amount of movement per pulse is determined by Entry.setProgressPulseStep).

resetImContext
void resetImContext()

Reset the input method context of the entry if needed.

setActivatesDefault
void setActivatesDefault(bool setting)

If setting is TRUE, pressing Enter in the entry will activate the default widget for the window containing the entry. This usually means that the dialog box containing the entry will be closed, since the default widget is usually one of the dialog buttons.

setAlignment
void setAlignment(float xalign)

Sets the alignment for the contents of the entry. This controls the horizontal positioning of the contents when the displayed text is shorter than the width of the entry.

setAttributes
void setAttributes(PgAttributeList attrs)

Sets a PangoAttrList; the attributes in the list are applied to the entry text.

setBuffer
void setBuffer(EntryBuffer buffer)

Set the gtk.EntryBuffer object which holds the text for this widget.

setCompletion
void setCompletion(EntryCompletion completion)

Sets completion to be the auxiliary completion object to use with entry. All further configuration of the completion mechanism is done on completion using the gtk.EntryCompletion API. Completion is disabled if completion is set to NULL.

setCursorHadjustment
void setCursorHadjustment(Adjustment adjustment)

Hooks up an adjustment to the cursor position in an entry, so that when the cursor is moved, the adjustment is scrolled to show that position. See ScrolledWindow.getHadjustment for a typical way of obtaining the adjustment.

setHasFrame
void setHasFrame(bool setting)

Sets whether the entry has a beveled frame around it.

setIconActivatable
void setIconActivatable(GtkEntryIconPosition iconPos, bool activatable)

Sets whether the icon is activatable.

setIconDragSource
void setIconDragSource(GtkEntryIconPosition iconPos, TargetList targetList, GdkDragAction actions)

Sets up the icon at the given position so that GTK+ will start a drag operation when the user clicks and drags the icon.

setIconFromGicon
void setIconFromGicon(GtkEntryIconPosition iconPos, IconIF icon)

Sets the icon shown in the entry at the specified position from the current icon theme. If the icon isn’t known, a “broken image” icon will be displayed instead.

setIconFromIconName
void setIconFromIconName(GtkEntryIconPosition iconPos, string iconName)

Sets the icon shown in the entry at the specified position from the current icon theme.

setIconFromPixbuf
void setIconFromPixbuf(GtkEntryIconPosition iconPos, Pixbuf pixbuf)

Sets the icon shown in the specified position using a pixbuf.

setIconFromStock
void setIconFromStock(GtkEntryIconPosition iconPos, string stockId)

Sets the icon shown in the entry at the specified position from a stock image.

setIconSensitive
void setIconSensitive(GtkEntryIconPosition iconPos, bool sensitive)

Sets the sensitivity for the specified icon.

setIconTooltipMarkup
void setIconTooltipMarkup(GtkEntryIconPosition iconPos, string tooltip)

Sets tooltip as the contents of the tooltip for the icon at the specified position. tooltip is assumed to be marked up with the [Pango text markup language]PangoMarkupFormat.

setIconTooltipText
void setIconTooltipText(GtkEntryIconPosition iconPos, string tooltip)

Sets tooltip as the contents of the tooltip for the icon at the specified position.

setInnerBorder
void setInnerBorder(Border border)

Sets entry’s inner-border property to border, or clears it if NULL is passed. The inner-border is the area around the entry’s text, but inside its frame.

setInputHints
void setInputHints(GtkInputHints hints)

Sets the input-hints property, which allows input methods to fine-tune their behaviour.

setInputPurpose
void setInputPurpose(GtkInputPurpose purpose)

Sets the input-purpose property which can be used by on-screen keyboards and other input methods to adjust their behaviour.

setInvisibleChar
void setInvisibleChar(dchar ch)

Sets the character to use in place of the actual text when Entry.setVisibility has been called to set text visibility to FALSE. i.e. this is the character used in “password mode” to show the user how many characters have been typed. By default, GTK+ picks the best invisible char available in the current font. If you set the invisible char to 0, then the user will get no feedback at all; there will be no text on the screen as they type.

setMaxLength
void setMaxLength(int max)

Sets the maximum allowed length of the contents of the widget. If the current contents are longer than the given length, then they will be truncated to fit.

setMaxWidthChars
void setMaxWidthChars(int nChars)

Sets the desired maximum width in characters of entry.

setOverwriteMode
void setOverwriteMode(bool overwrite)

Sets whether the text is overwritten when typing in the gtk.Entry

setPlaceholderText
void setPlaceholderText(string text)

Sets text to be displayed in entry when it is empty and unfocused. This can be used to give a visual hint of the expected contents of the gtk.Entry

setProgressFraction
void setProgressFraction(double fraction)

Causes the entry’s progress indicator to “fill in” the given fraction of the bar. The fraction should be between 0.0 and 1.0, inclusive.

setProgressPulseStep
void setProgressPulseStep(double fraction)

Sets the fraction of total entry width to move the progress bouncing block for each call to Entry.progressPulse.

setTabs
void setTabs(PgTabArray tabs)

Sets a PangoTabArray; the tabstops in the array are applied to the entry text.

setText
void setText(string text)

Sets the text in the widget to the given value, replacing the current contents.

setVisibility
void setVisibility(bool visible)

Sets whether the contents of the entry are visible or not. When visibility is set to FALSE, characters are displayed as the invisible char, and will also appear that way when the text in the entry widget is copied elsewhere.

setWidthChars
void setWidthChars(int nChars)

Changes the size request of the entry to be about the right size for n_chars characters. Note that it changes the size request, the size can still be affected by how you pack the widget into containers. If n_chars is -1, the size reverts to the default entry size.

textIndexToLayoutIndex
int textIndexToLayoutIndex(int textIndex)

Converts from a position in the entry contents (returned by Entry.getText) to a position in the entry’s gtk.Layout (returned by Entry.getLayout, with text retrieved via Layout.getText).

unsetInvisibleChar
void unsetInvisibleChar()

Unsets the invisible char previously set with Entry.setInvisibleChar. So that the default invisible char is used again.

addOnActivate
gulong addOnActivate(void delegate(Entry) dlg, ConnectFlags connectFlags)

The ::activate signal is emitted when the user hits the Enter key.

addOnBackspace
gulong addOnBackspace(void delegate(Entry) dlg, ConnectFlags connectFlags)

The ::backspace signal is a [keybinding signal]GtkBindingSignal which gets emitted when the user asks for it.

addOnCopyClipboard
gulong addOnCopyClipboard(void delegate(Entry) dlg, ConnectFlags connectFlags)

The ::copy-clipboard signal is a [keybinding signal]GtkBindingSignal which gets emitted to copy the selection to the clipboard.

addOnCutClipboard
gulong addOnCutClipboard(void delegate(Entry) dlg, ConnectFlags connectFlags)

The ::cut-clipboard signal is a [keybinding signal]GtkBindingSignal which gets emitted to cut the selection to the clipboard.

addOnDeleteFromCursor
gulong addOnDeleteFromCursor(void delegate(GtkDeleteType, int, Entry) dlg, ConnectFlags connectFlags)

The ::delete-from-cursor signal is a [keybinding signal]GtkBindingSignal which gets emitted when the user initiates a text deletion.

addOnIconPress
gulong addOnIconPress(void delegate(GtkEntryIconPosition, GdkEventButton*, Entry) dlg, ConnectFlags connectFlags)

The ::icon-press signal is emitted when an activatable icon is clicked.

addOnIconPress
gulong addOnIconPress(void delegate(GtkEntryIconPosition, Event, Entry) dlg, ConnectFlags connectFlags)

The ::icon-press signal is emitted when an activatable icon is clicked.

addOnIconRelease
gulong addOnIconRelease(void delegate(GtkEntryIconPosition, GdkEventButton*, Entry) dlg, ConnectFlags connectFlags)

The ::icon-release signal is emitted on the button release from a mouse click over an activatable icon.

addOnIconRelease
gulong addOnIconRelease(void delegate(GtkEntryIconPosition, Event, Entry) dlg, ConnectFlags connectFlags)

The ::icon-release signal is emitted on the button release from a mouse click over an activatable icon.

addOnInsertAtCursor
gulong addOnInsertAtCursor(void delegate(string, Entry) dlg, ConnectFlags connectFlags)

The ::insert-at-cursor signal is a [keybinding signal]GtkBindingSignal which gets emitted when the user initiates the insertion of a fixed string at the cursor.

addOnInsertEmoji
gulong addOnInsertEmoji(void delegate(Entry) dlg, ConnectFlags connectFlags)

The ::insert-emoji signal is a [keybinding signal]GtkBindingSignal which gets emitted to present the Emoji chooser for the entry.

addOnMoveCursor
gulong addOnMoveCursor(void delegate(GtkMovementStep, int, bool, Entry) dlg, ConnectFlags connectFlags)

The ::move-cursor signal is a [keybinding signal]GtkBindingSignal which gets emitted when the user initiates a cursor movement. If the cursor is not visible in entry, this signal causes the viewport to be moved instead.

addOnPasteClipboard
gulong addOnPasteClipboard(void delegate(Entry) dlg, ConnectFlags connectFlags)

The ::paste-clipboard signal is a [keybinding signal]GtkBindingSignal which gets emitted to paste the contents of the clipboard into the text view.

addOnPopulatePopup
gulong addOnPopulatePopup(void delegate(Widget, Entry) dlg, ConnectFlags connectFlags)

The ::populate-popup signal gets emitted before showing the context menu of the entry.

addOnPreeditChanged
gulong addOnPreeditChanged(void delegate(string, Entry) dlg, ConnectFlags connectFlags)

If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.

addOnToggleOverwrite
gulong addOnToggleOverwrite(void delegate(Entry) dlg, ConnectFlags connectFlags)

The ::toggle-overwrite signal is a [keybinding signal]GtkBindingSignal which gets emitted to toggle the overwrite mode of the entry.

From OrientableIF

getOrientableStruct
GtkOrientable* getOrientableStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
getOrientation
GtkOrientation getOrientation()

Retrieves the orientation of the orientable.

setOrientation
void setOrientation(GtkOrientation orientation)

Sets the orientation of the orientable.