SpinBox
Inherits: Range < Control < CanvasItem < Actor < Object
An input field for numbers.
Description
Section titled “Description”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 to 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.
spin_box : SpinBox = SpinBox.new()add_child(spin_box)line_edit : LineEdit = spin_box.get_line_edit()line_edit.context_menu_enabled = falsespin_box.alignment = HORIZONTAL_ALIGNMENT_RIGHTSee 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 actor. 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.set_drag_forwarding() on the actor returned by get_line_edit().
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| HorizontalAlignment | alignment | 0 |
| bool | custom_arrow_round | false |
| float | custom_arrow_step | 0.0 |
| bool | editable | true |
| String | prefix | "" |
| bool | select_all_on_focus | false |
| Control.SizeFlags | size_flags_vertical | 1 |
| float | step | 1.0 |
| String | suffix | "" |
| bool | update_on_text_changed | false |
Methods
Section titled “Methods”| Returns | Method |
|---|---|
| void | apply() |
| LineEdit | get_line_edit() |
Property descriptions
Section titled “Property descriptions”alignment
Section titled “alignment”HorizontalAlignment alignment = 0
Setter/getter: set_horizontal_alignment(), get_horizontal_alignment()
Changes the alignment of the underlying LineEdit.
custom_arrow_round
Section titled “custom_arrow_round”bool custom_arrow_round = false
Setter/getter: set_custom_arrow_round(), is_custom_arrow_rounding()
If true, the value will be rounded to a multiple of custom_arrow_step when interacting with the arrow buttons. Otherwise, increments the value by custom_arrow_step and then rounds it according to Range.step.
custom_arrow_step
Section titled “custom_arrow_step”float custom_arrow_step = 0.0
Setter/getter: set_custom_arrow_step(), get_custom_arrow_step()
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.
editable
Section titled “editable”bool editable = true
Setter/getter: set_editable(), is_editable()
If true, the SpinBox will be editable. Otherwise, it will be read only.
prefix
Section titled “prefix”String prefix = ""
Setter/getter: set_prefix(), get_prefix()
Adds the specified prefix string before the numerical value of the SpinBox.
select_all_on_focus
Section titled “select_all_on_focus”bool select_all_on_focus = false
Setter/getter: set_select_all_on_focus(), is_select_all_on_focus()
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.
size_flags_vertical
Section titled “size_flags_vertical”Control.SizeFlags size_flags_vertical = 1
Setter/getter: set_v_size_flags(), get_v_size_flags()
No description yet.
float step = 1.0
Setter/getter: set_step(), get_step()
No description yet.
suffix
Section titled “suffix”String suffix = ""
Setter/getter: set_suffix(), get_suffix()
Adds the specified suffix string after the numerical value of the SpinBox.
update_on_text_changed
Section titled “update_on_text_changed”bool update_on_text_changed = false
Setter/getter: set_update_on_text_changed(), get_update_on_text_changed()
Sets the value of the Range for this SpinBox when the LineEdit text is changed instead of submitted. See LineEdit.text_changed and LineEdit.text_submitted.
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.
Method descriptions
Section titled “Method descriptions”void 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 LineEdit.text_submitted to be emitted and its currently contained expression to be evaluated.
get_line_edit
Section titled “get_line_edit”LineEdit get_line_edit()
Returns the LineEdit instance from this SpinBox. You can use it to access properties and methods of LineEdit.
Warning: This is a required internal actor, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.visible property.