class_spinbox.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. :github_url: hide
  2. .. meta::
  3. :keywords: number, numeric, input
  4. .. DO NOT EDIT THIS FILE!!!
  5. .. Generated automatically from Godot engine sources.
  6. .. Generator: https://github.com/godotengine/godot/tree/4.3/doc/tools/make_rst.py.
  7. .. XML source: https://github.com/godotengine/godot/tree/4.3/doc/classes/SpinBox.xml.
  8. .. _class_SpinBox:
  9. SpinBox
  10. =======
  11. **Inherits:** :ref:`Range<class_Range>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  12. An input field for numbers.
  13. .. rst-class:: classref-introduction-group
  14. Description
  15. -----------
  16. **SpinBox** is a numerical input text field. It allows entering integers and floating-point numbers.
  17. \ **Example:**\
  18. .. tabs::
  19. .. code-tab:: gdscript
  20. var spin_box = SpinBox.new()
  21. add_child(spin_box)
  22. var line_edit = spin_box.get_line_edit()
  23. line_edit.context_menu_enabled = false
  24. spin_box.horizontal_alignment = LineEdit.HORIZONTAL_ALIGNMENT_RIGHT
  25. .. code-tab:: csharp
  26. var spinBox = new SpinBox();
  27. AddChild(spinBox);
  28. var lineEdit = spinBox.GetLineEdit();
  29. lineEdit.ContextMenuEnabled = false;
  30. spinBox.AlignHorizontal = LineEdit.HorizontalAlignEnum.Right;
  31. The above code will create a **SpinBox**, disable context menu on it and set the text alignment to right.
  32. See :ref:`Range<class_Range>` class for more options over the **SpinBox**.
  33. \ **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.
  34. \ **Note:** **SpinBox** relies on an underlying :ref:`LineEdit<class_LineEdit>` node. To theme a **SpinBox**'s background, add theme items for :ref:`LineEdit<class_LineEdit>` and customize them.
  35. \ **Note:** If you want to implement drag and drop for the underlying :ref:`LineEdit<class_LineEdit>`, you can use :ref:`Control.set_drag_forwarding<class_Control_method_set_drag_forwarding>` on the node returned by :ref:`get_line_edit<class_SpinBox_method_get_line_edit>`.
  36. .. rst-class:: classref-reftable-group
  37. Properties
  38. ----------
  39. .. table::
  40. :widths: auto
  41. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  42. | :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` | :ref:`alignment<class_SpinBox_property_alignment>` | ``0`` |
  43. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`custom_arrow_step<class_SpinBox_property_custom_arrow_step>` | ``0.0`` |
  45. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`editable<class_SpinBox_property_editable>` | ``true`` |
  47. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  48. | :ref:`String<class_String>` | :ref:`prefix<class_SpinBox_property_prefix>` | ``""`` |
  49. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  50. | :ref:`bool<class_bool>` | :ref:`select_all_on_focus<class_SpinBox_property_select_all_on_focus>` | ``false`` |
  51. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  52. | |bitfield|\[:ref:`SizeFlags<enum_Control_SizeFlags>`\] | size_flags_vertical | ``1`` (overrides :ref:`Control<class_Control_property_size_flags_vertical>`) |
  53. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  54. | :ref:`float<class_float>` | step | ``1.0`` (overrides :ref:`Range<class_Range_property_step>`) |
  55. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  56. | :ref:`String<class_String>` | :ref:`suffix<class_SpinBox_property_suffix>` | ``""`` |
  57. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`update_on_text_changed<class_SpinBox_property_update_on_text_changed>` | ``false`` |
  59. +-------------------------------------------------------------------+------------------------------------------------------------------------------+------------------------------------------------------------------------------+
  60. .. rst-class:: classref-reftable-group
  61. Methods
  62. -------
  63. .. table::
  64. :widths: auto
  65. +---------------------------------+----------------------------------------------------------------+
  66. | |void| | :ref:`apply<class_SpinBox_method_apply>`\ (\ ) |
  67. +---------------------------------+----------------------------------------------------------------+
  68. | :ref:`LineEdit<class_LineEdit>` | :ref:`get_line_edit<class_SpinBox_method_get_line_edit>`\ (\ ) |
  69. +---------------------------------+----------------------------------------------------------------+
  70. .. rst-class:: classref-reftable-group
  71. Theme Properties
  72. ----------------
  73. .. table::
  74. :widths: auto
  75. +-----------------------------------+------------------------------------------------+
  76. | :ref:`Texture2D<class_Texture2D>` | :ref:`updown<class_SpinBox_theme_icon_updown>` |
  77. +-----------------------------------+------------------------------------------------+
  78. .. rst-class:: classref-section-separator
  79. ----
  80. .. rst-class:: classref-descriptions-group
  81. Property Descriptions
  82. ---------------------
  83. .. _class_SpinBox_property_alignment:
  84. .. rst-class:: classref-property
  85. :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` **alignment** = ``0`` :ref:`🔗<class_SpinBox_property_alignment>`
  86. .. rst-class:: classref-property-setget
  87. - |void| **set_horizontal_alignment**\ (\ value\: :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>`\ )
  88. - :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` **get_horizontal_alignment**\ (\ )
  89. Changes the alignment of the underlying :ref:`LineEdit<class_LineEdit>`.
  90. .. rst-class:: classref-item-separator
  91. ----
  92. .. _class_SpinBox_property_custom_arrow_step:
  93. .. rst-class:: classref-property
  94. :ref:`float<class_float>` **custom_arrow_step** = ``0.0`` :ref:`🔗<class_SpinBox_property_custom_arrow_step>`
  95. .. rst-class:: classref-property-setget
  96. - |void| **set_custom_arrow_step**\ (\ value\: :ref:`float<class_float>`\ )
  97. - :ref:`float<class_float>` **get_custom_arrow_step**\ (\ )
  98. If not ``0``, :ref:`Range.value<class_Range_property_value>` will always be rounded to a multiple of :ref:`custom_arrow_step<class_SpinBox_property_custom_arrow_step>` when interacting with the arrow buttons of the **SpinBox**.
  99. .. rst-class:: classref-item-separator
  100. ----
  101. .. _class_SpinBox_property_editable:
  102. .. rst-class:: classref-property
  103. :ref:`bool<class_bool>` **editable** = ``true`` :ref:`🔗<class_SpinBox_property_editable>`
  104. .. rst-class:: classref-property-setget
  105. - |void| **set_editable**\ (\ value\: :ref:`bool<class_bool>`\ )
  106. - :ref:`bool<class_bool>` **is_editable**\ (\ )
  107. If ``true``, the **SpinBox** will be editable. Otherwise, it will be read only.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. _class_SpinBox_property_prefix:
  111. .. rst-class:: classref-property
  112. :ref:`String<class_String>` **prefix** = ``""`` :ref:`🔗<class_SpinBox_property_prefix>`
  113. .. rst-class:: classref-property-setget
  114. - |void| **set_prefix**\ (\ value\: :ref:`String<class_String>`\ )
  115. - :ref:`String<class_String>` **get_prefix**\ (\ )
  116. Adds the specified prefix string before the numerical value of the **SpinBox**.
  117. .. rst-class:: classref-item-separator
  118. ----
  119. .. _class_SpinBox_property_select_all_on_focus:
  120. .. rst-class:: classref-property
  121. :ref:`bool<class_bool>` **select_all_on_focus** = ``false`` :ref:`🔗<class_SpinBox_property_select_all_on_focus>`
  122. .. rst-class:: classref-property-setget
  123. - |void| **set_select_all_on_focus**\ (\ value\: :ref:`bool<class_bool>`\ )
  124. - :ref:`bool<class_bool>` **is_select_all_on_focus**\ (\ )
  125. If ``true``, the **SpinBox** will select the whole text when the :ref:`LineEdit<class_LineEdit>` gains focus. Clicking the up and down arrows won't trigger this behavior.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_SpinBox_property_suffix:
  129. .. rst-class:: classref-property
  130. :ref:`String<class_String>` **suffix** = ``""`` :ref:`🔗<class_SpinBox_property_suffix>`
  131. .. rst-class:: classref-property-setget
  132. - |void| **set_suffix**\ (\ value\: :ref:`String<class_String>`\ )
  133. - :ref:`String<class_String>` **get_suffix**\ (\ )
  134. Adds the specified suffix string after the numerical value of the **SpinBox**.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_SpinBox_property_update_on_text_changed:
  138. .. rst-class:: classref-property
  139. :ref:`bool<class_bool>` **update_on_text_changed** = ``false`` :ref:`🔗<class_SpinBox_property_update_on_text_changed>`
  140. .. rst-class:: classref-property-setget
  141. - |void| **set_update_on_text_changed**\ (\ value\: :ref:`bool<class_bool>`\ )
  142. - :ref:`bool<class_bool>` **get_update_on_text_changed**\ (\ )
  143. Sets the value of the :ref:`Range<class_Range>` for this **SpinBox** when the :ref:`LineEdit<class_LineEdit>` text is *changed* instead of *submitted*. See :ref:`LineEdit.text_changed<class_LineEdit_signal_text_changed>` and :ref:`LineEdit.text_submitted<class_LineEdit_signal_text_submitted>`.
  144. .. rst-class:: classref-section-separator
  145. ----
  146. .. rst-class:: classref-descriptions-group
  147. Method Descriptions
  148. -------------------
  149. .. _class_SpinBox_method_apply:
  150. .. rst-class:: classref-method
  151. |void| **apply**\ (\ ) :ref:`🔗<class_SpinBox_method_apply>`
  152. Applies the current value of this **SpinBox**.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_SpinBox_method_get_line_edit:
  156. .. rst-class:: classref-method
  157. :ref:`LineEdit<class_LineEdit>` **get_line_edit**\ (\ ) :ref:`🔗<class_SpinBox_method_get_line_edit>`
  158. Returns the :ref:`LineEdit<class_LineEdit>` instance from this **SpinBox**. You can use it to access properties and methods of :ref:`LineEdit<class_LineEdit>`.
  159. \ **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 :ref:`CanvasItem.visible<class_CanvasItem_property_visible>` property.
  160. .. rst-class:: classref-section-separator
  161. ----
  162. .. rst-class:: classref-descriptions-group
  163. Theme Property Descriptions
  164. ---------------------------
  165. .. _class_SpinBox_theme_icon_updown:
  166. .. rst-class:: classref-themeproperty
  167. :ref:`Texture2D<class_Texture2D>` **updown** :ref:`🔗<class_SpinBox_theme_icon_updown>`
  168. Sets a custom :ref:`Texture2D<class_Texture2D>` for up and down arrows of the **SpinBox**.
  169. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  170. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  171. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  172. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  173. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  174. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  175. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  176. .. |void| replace:: :abbr:`void (No return value.)`