SpinBox

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

SpinBox is a numerical input text field. It allows entering integers and floating-point numbers. The SpinBox also has up and down buttons that can be clicked increase or decrease the value. The value can also be changed by dragging the mouse up or down over the SpinBox's arrows.

Additionally, mathematical expressions can be entered. These are evaluated when the user presses Enter while editing the SpinBox's text field. This uses the Expression class to parse and evaluate the expression. The result of the expression is then set as the value of the SpinBox. Some examples of valid expressions are 5 + 2 * 3, pow(2, 4), and PI + sin(0.5). Expressions are case-sensitive.

Example: Create a SpinBox, disable its context menu and set its text alignment to right.

package main

import (
	"graphics.gd/classdb/GUI"
	"graphics.gd/classdb/Node"
	"graphics.gd/classdb/SpinBox"
)

func ExampleSpinBox(parent Node.Instance) {
	var spinBox = SpinBox.New()
	parent.AddChild(spinBox.AsNode())
	var lineEdit = spinBox.GetLineEdit()
	lineEdit.SetContextMenuEnabled(false)
	SpinBox.Advanced(spinBox).SetHorizontalAlignment(GUI.HorizontalAlignmentRight)
}

See Range class for more options over the SpinBox.

Note: With the SpinBox's context menu disabled, you can right-click the bottom half of the spinbox to set the value to its minimum, while right-clicking the top half sets the value to its maximum.

Note: SpinBox relies on an underlying LineEdit node. To theme a SpinBox's background, add theme items for LineEdit and customize them. The LineEdit has the SpinBoxInnerLineEdit theme variation, so that you can give it a distinct appearance from regular LineEdits.

Note: If you want to implement drag and drop for the underlying LineEdit, you can use Control.SetDragForwarding on the node returned by GetLineEdit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsSpinBox() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsCanvasItem

func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance

func (*Extension[T]) AsControl

func (self *Extension[T]) AsControl() Control.Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRange

func (self *Extension[T]) AsRange() Range.Instance

func (*Extension[T]) AsSpinBox

func (self *Extension[T]) AsSpinBox() Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.SpinBox

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) Alignment

func (self Instance) Alignment() GUI.HorizontalAlignment

Changes the alignment of the underlying LineEdit.

func (Instance) Apply

func (self Instance) Apply()

Applies the current value of this SpinBox. This is equivalent to pressing Enter while editing the LineEdit used by the SpinBox. This will cause OnLineedit.TextSubmitted to be emitted and its currently contained expression to be evaluated.

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsControl

func (self Instance) AsControl() Control.Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRange

func (self Instance) AsRange() Range.Instance

func (Instance) AsSpinBox

func (self Instance) AsSpinBox() Instance

func (Instance) CustomArrowStep

func (self Instance) CustomArrowStep() Float.X

If not 0, sets the step when interacting with the arrow buttons of the SpinBox.

Note: Range.Value will still be rounded to a multiple of Range.Step.

func (Instance) Editable

func (self Instance) Editable() bool

If true, the SpinBox will be editable. Otherwise, it will be read only.

func (Instance) GetLineEdit

func (self Instance) GetLineEdit() LineEdit.Instance

Returns the LineEdit instance from this SpinBox. You can use it to access properties and methods of LineEdit.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.Visible property.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) Prefix

func (self Instance) Prefix() string

Adds the specified prefix string before the numerical value of the SpinBox.

func (Instance) SelectAllOnFocus

func (self Instance) SelectAllOnFocus() bool

If true, the SpinBox will select the whole text when the LineEdit gains focus. Clicking the up and down arrows won't trigger this behavior.

func (Instance) SetAlignment

func (self Instance) SetAlignment(value GUI.HorizontalAlignment)

SetAlignment sets the property returned by [GetHorizontalAlignment].

func (Instance) SetCustomArrowStep

func (self Instance) SetCustomArrowStep(value Float.X)

SetCustomArrowStep sets the property returned by [GetCustomArrowStep].

func (Instance) SetEditable

func (self Instance) SetEditable(value bool)

SetEditable sets the property returned by [IsEditable].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetPrefix

func (self Instance) SetPrefix(value string)

SetPrefix sets the property returned by [GetPrefix].

func (Instance) SetSelectAllOnFocus

func (self Instance) SetSelectAllOnFocus(value bool)

SetSelectAllOnFocus sets the property returned by [IsSelectAllOnFocus].

func (Instance) SetSuffix

func (self Instance) SetSuffix(value string)

SetSuffix sets the property returned by [GetSuffix].

func (Instance) SetUpdateOnTextChanged

func (self Instance) SetUpdateOnTextChanged(value bool)

SetUpdateOnTextChanged sets the property returned by [GetUpdateOnTextChanged].

func (Instance) Suffix

func (self Instance) Suffix() string

Adds the specified suffix string after the numerical value of the SpinBox.

func (Instance) UpdateOnTextChanged

func (self Instance) UpdateOnTextChanged() bool

Sets the value of the Range for this SpinBox when the LineEdit text is changed instead of submitted. See OnLineedit.TextChanged and OnLineedit.TextSubmitted.

Note: If set to true, this will interfere with entering mathematical expressions in the SpinBox. The SpinBox will try to evaluate the expression as you type, which means symbols like a trailing + are removed immediately by the expression being evaluated.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL