Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
SpinBox¶
Inherits: Range < Control < CanvasItem < Node < Object
数字的输入字段。
Description¶
SpinBox 是一种用于输入数值的文本字段,允许输入整数和浮点数。
示例:
var spin_box = SpinBox.new()
add_child(spin_box)
var line_edit = spin_box.get_line_edit()
line_edit.context_menu_enabled = false
spin_box.horizontal_alignment = LineEdit.HORIZONTAL_ALIGNMENT_RIGHT
var spinBox = new SpinBox();
AddChild(spinBox);
var lineEdit = spinBox.GetLineEdit();
lineEdit.ContextMenuEnabled = false;
spinBox.AlignHorizontal = LineEdit.HorizontalAlignEnum.Right;
上面的代码会创建一个 SpinBox,禁用其中的上下文菜单,并将文本设置为右对齐。
SpinBox 的更多选项见 Range 类。
注意:SpinBox 依赖底层的 LineEdit 节点。要为 SpinBox 的背景设置主题,请为 LineEdit 添加主题项目并进行自定义。
注意:如果你想要为底层的 LineEdit 实现拖放,可以对 get_line_edit 所返回的节点使用 Control.set_drag_forwarding。
Properties¶
|
||
|
||
|
||
|
||
|
||
BitField<SizeFlags> |
size_flags_vertical |
|
step |
|
|
|
||
|
Methods¶
void |
apply ( ) |
get_line_edit ( ) |
Theme Properties¶
Property Descriptions¶
HorizontalAlignment alignment = 0
void set_horizontal_alignment ( HorizontalAlignment value )
HorizontalAlignment get_horizontal_alignment ( )
更改底层 LineEdit 的对齐方式。
float custom_arrow_step = 0.0
如果不是 0
,则在与 SpinBox 的箭头按钮交互时,value
将始终四舍五入为 custom_arrow_step
的倍数。
bool editable = true
如果为 true
,则 SpinBox 将是可编辑的。否则,它将是只读的。
String prefix = ""
在 SpinBox 的数值前添加指定的 prefix
字符串。
bool select_all_on_focus = false
如果为 true
,则该 SpinBox 会在 LineEdit 获得焦点时选中整个文本。点击上下箭头不会触发这种行为。
String suffix = ""
在 SpinBox 的数值后添加指定的 suffix
字符串。
bool update_on_text_changed = false
当 LineEdit 的文本发生变化而不是被提交时,设置这个 SpinBox 的 Range 的值。见 LineEdit.text_changed 和 LineEdit.text_submitted。
Method Descriptions¶
void apply ( )
应用此 SpinBox 的当前值。
LineEdit get_line_edit ( )