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 ¶
- type Advanced
- type Any
- type Extension
- func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
- func (self *Extension[T]) AsControl() Control.Instance
- func (self *Extension[T]) AsNode() Node.Instance
- func (self *Extension[T]) AsObject() [1]gd.Object
- func (self *Extension[T]) AsRange() Range.Instance
- func (self *Extension[T]) AsSpinBox() Instance
- type ID
- type Instance
- func (self Instance) Alignment() GUI.HorizontalAlignment
- func (self Instance) Apply()
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsControl() Control.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRange() Range.Instance
- func (self Instance) AsSpinBox() Instance
- func (self Instance) CustomArrowStep() Float.X
- func (self Instance) Editable() bool
- func (self Instance) GetLineEdit() LineEdit.Instance
- func (self Instance) ID() ID
- func (self Instance) Prefix() string
- func (self Instance) SelectAllOnFocus() bool
- func (self Instance) SetAlignment(value GUI.HorizontalAlignment)
- func (self Instance) SetCustomArrowStep(value Float.X)
- func (self Instance) SetEditable(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetPrefix(value string)
- func (self Instance) SetSelectAllOnFocus(value bool)
- func (self Instance) SetSuffix(value string)
- func (self Instance) SetUpdateOnTextChanged(value bool)
- func (self Instance) Suffix() string
- func (self Instance) UpdateOnTextChanged() bool
- func (self Instance) Virtual(name string) reflect.Value
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 Extension ¶
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
type 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.
type Instance ¶
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 (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) CustomArrowStep ¶
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) GetLineEdit ¶
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) Prefix ¶
Adds the specified prefix string before the numerical value of the SpinBox.
func (Instance) SelectAllOnFocus ¶
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 ¶
SetCustomArrowStep sets the property returned by [GetCustomArrowStep].
func (Instance) SetEditable ¶
SetEditable sets the property returned by [IsEditable].
func (Instance) SetSelectAllOnFocus ¶
SetSelectAllOnFocus sets the property returned by [IsSelectAllOnFocus].
func (Instance) SetUpdateOnTextChanged ¶
SetUpdateOnTextChanged sets the property returned by [GetUpdateOnTextChanged].
func (Instance) UpdateOnTextChanged ¶
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.