SpinBox
Inherits: Range < Control < CanvasItem < Entity < Object
Description
Section titled “Description”An input field for numbers.
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.
var spinBox = new SpinBox();AddChild(spinBox);var lineEdit = spinBox.GetLineEdit();lineEdit.ContextMenuEnabled = false;spinBox.AlignHorizontal = LineEdit.HorizontalAlignEnum.Right;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 and audio feedback on its text field, 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 node 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 | format |
"" |
| Entity.AutoTranslateMode | format_auto_translate_mode |
2 |
| String | plural_format |
|
| bool | select_all_on_focus |
false |
| BitField[Control.SizeFlags] | size_flags_vertical |
1 (overrides Control) |
| float | step |
1.0 (overrides Range) |
| bool | update_on_text_changed |
false |
Methods
Section titled “Methods”| Returns | Method |
|---|---|
| void | apply() |
| LineEdit | get_line_edit() |
Theme items
Section titled “Theme items”down_disabled_icon_modulate
Color down_disabled_icon_modulate (color) = Color(0.875, 0.875, 0.875, 0.5)
down_hover_icon_modulate
Color down_hover_icon_modulate (color) = Color(0.95, 0.95, 0.95, 1)
down_icon_modulate
Color down_icon_modulate (color) = Color(0.875, 0.875, 0.875, 1)
down_pressed_icon_modulate
Color down_pressed_icon_modulate (color) = Color(0.95, 0.95, 0.95, 1)
up_disabled_icon_modulate
Color up_disabled_icon_modulate (color) = Color(0.875, 0.875, 0.875, 0.5)
up_hover_icon_modulate
Color up_hover_icon_modulate (color) = Color(0.95, 0.95, 0.95, 1)
up_icon_modulate
Color up_icon_modulate (color) = Color(0.875, 0.875, 0.875, 1)
up_pressed_icon_modulate
Color up_pressed_icon_modulate (color) = Color(0.95, 0.95, 0.95, 1)
buttons_vertical_separation
int buttons_vertical_separation (constant) = 0
buttons_width
int buttons_width (constant) = 16
field_and_buttons_separation
int field_and_buttons_separation (constant) = 2
icon_max_width
int icon_max_width (constant) = 0
down
Texture2D down (icon)
down_disabled
Texture2D down_disabled (icon)
down_hover
Texture2D down_hover (icon)
down_pressed
Texture2D down_pressed (icon)
up
Texture2D up (icon)
up_disabled
Texture2D up_disabled (icon)
up_hover
Texture2D up_hover (icon)
up_pressed
Texture2D up_pressed (icon)
focus_sound
AudioStream focus_sound (sound)
pressed_disabled_sound
AudioStream pressed_disabled_sound (sound)
pressed_sound
AudioStream pressed_sound (sound)
down_background
StyleBox down_background (style)
down_background_disabled
StyleBox down_background_disabled (style)
down_background_hovered
StyleBox down_background_hovered (style)
down_background_pressed
StyleBox down_background_pressed (style)
field_and_buttons_separator
StyleBox field_and_buttons_separator (style)
up_background
StyleBox up_background (style)
up_background_disabled
StyleBox up_background_disabled (style)
up_background_hovered
StyleBox up_background_hovered (style)
up_background_pressed
StyleBox up_background_pressed (style)
up_down_buttons_separator
StyleBox up_down_buttons_separator (style)
Property descriptions
Section titled “Property descriptions”alignment
HorizontalAlignment alignment = 0
Changes the alignment of the underlying LineEdit.
custom_arrow_round
bool custom_arrow_round = false
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
float custom_arrow_step = 0.0
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
bool editable = true
If true, the SpinBox will be editable. Otherwise, it will be read only.
format
String format = ""
The formatting of the displayed numeric value, using the same rules as String’s % operator. If empty, the value is displayed with no special formatting. If the format string is invalid, the SpinBox will display "<Invalid>", with the error message available as a configuration warning.
The following format strings can be used as examples:
-
"(%s)"displays as a number in parentheses (e.g.(6.9)). -
"%d ms"displays as an integer with milliseconds unit (e.g.420 ms). -
"%0.2f%%"displays as a percentage, with 2 decimal places of precision (e.g.21.37%).
format_auto_translate_mode
Entity.AutoTranslateMode format_auto_translate_mode = 2
Auto-translation mode for the format. Useful when the format has a word that can be translated.
plural_format
String plural_format
Plural version of format. Used only if format is not empty and format_auto_translate_mode is not disabled. See also Object.tr_n().
select_all_on_focus
bool select_all_on_focus = false
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.
update_on_text_changed
bool update_on_text_changed = false
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”apply
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
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 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.
