class_lineedit.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the LineEdit.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_LineEdit:
  5. LineEdit
  6. ========
  7. **Inherits:** :ref:`Control<class_control>` **<** :ref:`CanvasItem<class_canvasitem>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Control that provides single line string editing.
  12. Member Functions
  13. ----------------
  14. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  15. | void | :ref:`append_at_cursor<class_LineEdit_append_at_cursor>` **(** :ref:`String<class_string>` text **)** |
  16. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`clear<class_LineEdit_clear>` **(** **)** |
  18. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`bool<class_bool>` | :ref:`cursor_get_blink_enabled<class_LineEdit_cursor_get_blink_enabled>` **(** **)** const |
  20. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`float<class_float>` | :ref:`cursor_get_blink_speed<class_LineEdit_cursor_get_blink_speed>` **(** **)** const |
  22. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`cursor_set_blink_enabled<class_LineEdit_cursor_set_blink_enabled>` **(** :ref:`bool<class_bool>` enabled **)** |
  24. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`cursor_set_blink_speed<class_LineEdit_cursor_set_blink_speed>` **(** :ref:`float<class_float>` blink_speed **)** |
  26. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`int<class_int>` | :ref:`get_align<class_LineEdit_get_align>` **(** **)** const |
  28. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`get_cursor_position<class_LineEdit_get_cursor_position>` **(** **)** const |
  30. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`get_expand_to_text_length<class_LineEdit_get_expand_to_text_length>` **(** **)** const |
  32. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_max_length<class_LineEdit_get_max_length>` **(** **)** const |
  34. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`PopupMenu<class_popupmenu>` | :ref:`get_menu<class_LineEdit_get_menu>` **(** **)** const |
  36. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`String<class_string>` | :ref:`get_placeholder<class_LineEdit_get_placeholder>` **(** **)** const |
  38. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`get_placeholder_alpha<class_LineEdit_get_placeholder_alpha>` **(** **)** const |
  40. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`String<class_string>` | :ref:`get_text<class_LineEdit_get_text>` **(** **)** const |
  42. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`is_editable<class_LineEdit_is_editable>` **(** **)** const |
  44. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`is_secret<class_LineEdit_is_secret>` **(** **)** const |
  46. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`menu_option<class_LineEdit_menu_option>` **(** :ref:`int<class_int>` option **)** |
  48. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`select<class_LineEdit_select>` **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)** |
  50. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`select_all<class_LineEdit_select_all>` **(** **)** |
  52. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_align<class_LineEdit_set_align>` **(** :ref:`int<class_int>` align **)** |
  54. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_cursor_position<class_LineEdit_set_cursor_position>` **(** :ref:`int<class_int>` position **)** |
  56. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_editable<class_LineEdit_set_editable>` **(** :ref:`bool<class_bool>` enabled **)** |
  58. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_expand_to_text_length<class_LineEdit_set_expand_to_text_length>` **(** :ref:`bool<class_bool>` enabled **)** |
  60. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_max_length<class_LineEdit_set_max_length>` **(** :ref:`int<class_int>` chars **)** |
  62. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`set_placeholder<class_LineEdit_set_placeholder>` **(** :ref:`String<class_string>` text **)** |
  64. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`set_placeholder_alpha<class_LineEdit_set_placeholder_alpha>` **(** :ref:`float<class_float>` alpha **)** |
  66. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`set_secret<class_LineEdit_set_secret>` **(** :ref:`bool<class_bool>` enabled **)** |
  68. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`set_text<class_LineEdit_set_text>` **(** :ref:`String<class_string>` text **)** |
  70. +------------------------------------+------------------------------------------------------------------------------------------------------------------------+
  71. Signals
  72. -------
  73. .. _class_LineEdit_text_changed:
  74. - **text_changed** **(** :ref:`String<class_string>` text **)**
  75. Emitted when the text changes.
  76. .. _class_LineEdit_text_entered:
  77. - **text_entered** **(** :ref:`String<class_string>` text **)**
  78. Emitted when the user presses KEY_ENTER on the ``LineEdit``.
  79. Member Variables
  80. ----------------
  81. .. _class_LineEdit_align:
  82. - :ref:`int<class_int>` **align** - Text alignment as defined in the ALIGN\_\* enum.
  83. .. _class_LineEdit_caret_blink:
  84. - :ref:`bool<class_bool>` **caret_blink** - If ``true`` the caret (visual cursor) blinks.
  85. .. _class_LineEdit_caret_blink_speed:
  86. - :ref:`float<class_float>` **caret_blink_speed** - Duration (in seconds) of a caret's blinking cycle.
  87. .. _class_LineEdit_editable:
  88. - :ref:`bool<class_bool>` **editable** - If ``false`` existing text cannot be modified and new text cannot be added.
  89. .. _class_LineEdit_expand_to_len:
  90. - :ref:`bool<class_bool>` **expand_to_len** - If ``true`` the :ref:`LineEdit<class_lineedit>` width will increase to stay longer than the :ref:`text<class_LineEdit_text>`. It will **not** compress if the :ref:`text<class_LineEdit_text>` is shortened.
  91. .. _class_LineEdit_focus_mode:
  92. - :ref:`int<class_int>` **focus_mode** - Defines how the :ref:`LineEdit<class_lineedit>` can grab focus (Keyboard and mouse, only keyboard, or none). See ``enum FocusMode`` in :ref:`Control<class_control>` for details.
  93. .. _class_LineEdit_max_length:
  94. - :ref:`int<class_int>` **max_length** - Maximum amount of characters that can be entered inside the :ref:`LineEdit<class_lineedit>`. If ``0``, there is no limit.
  95. .. _class_LineEdit_placeholder_alpha:
  96. - :ref:`float<class_float>` **placeholder_alpha** - Opacity of the :ref:`placeholder_text<class_LineEdit_placeholder_text>`. From ``0`` to ``1``.
  97. .. _class_LineEdit_placeholder_text:
  98. - :ref:`String<class_string>` **placeholder_text** - Text shown when the :ref:`LineEdit<class_lineedit>` is empty. It is **not** the :ref:`LineEdit<class_lineedit>`'s default value (see :ref:`text<class_LineEdit_text>`).
  99. .. _class_LineEdit_secret:
  100. - :ref:`bool<class_bool>` **secret** - If ``true`` every character is shown as "\*".
  101. .. _class_LineEdit_text:
  102. - :ref:`String<class_string>` **text** - String value of the :ref:`LineEdit<class_lineedit>`.
  103. Numeric Constants
  104. -----------------
  105. - **ALIGN_LEFT** = **0** --- Aligns the text on the left hand side of the :ref:`LineEdit<class_lineedit>`.
  106. - **ALIGN_CENTER** = **1** --- Centers the text in the middle of the :ref:`LineEdit<class_lineedit>`.
  107. - **ALIGN_RIGHT** = **2** --- Aligns the text on the right hand side of the :ref:`LineEdit<class_lineedit>`.
  108. - **ALIGN_FILL** = **3** --- Stretches whitespaces to fit the :ref:`LineEdit<class_lineedit>`'s width.
  109. - **MENU_CUT** = **0** --- Cuts (Copies and clears) the selected text.
  110. - **MENU_COPY** = **1** --- Copies the selected text.
  111. - **MENU_PASTE** = **2** --- Pastes the clipboard text over the selected text (or at the cursor's position).
  112. - **MENU_CLEAR** = **3** --- Erases the whole Linedit text.
  113. - **MENU_SELECT_ALL** = **4** --- Selects the whole Linedit text.
  114. - **MENU_UNDO** = **5** --- Undoes the previous action.
  115. - **MENU_MAX** = **6**
  116. Description
  117. -----------
  118. LineEdit provides a single line string editor, used for text fields.
  119. Member Function Description
  120. ---------------------------
  121. .. _class_LineEdit_append_at_cursor:
  122. - void **append_at_cursor** **(** :ref:`String<class_string>` text **)**
  123. Adds ``text`` after the cursor. If the resulting value is longer than :ref:`max_length<class_LineEdit_max_length>`, nothing happens.
  124. .. _class_LineEdit_clear:
  125. - void **clear** **(** **)**
  126. Erases the :ref:`LineEdit<class_lineedit>` text.
  127. .. _class_LineEdit_cursor_get_blink_enabled:
  128. - :ref:`bool<class_bool>` **cursor_get_blink_enabled** **(** **)** const
  129. Gets whether the line edit caret is blinking.
  130. .. _class_LineEdit_cursor_get_blink_speed:
  131. - :ref:`float<class_float>` **cursor_get_blink_speed** **(** **)** const
  132. Gets the line edit caret blink speed.
  133. .. _class_LineEdit_cursor_set_blink_enabled:
  134. - void **cursor_set_blink_enabled** **(** :ref:`bool<class_bool>` enabled **)**
  135. Set the line edit caret to blink.
  136. .. _class_LineEdit_cursor_set_blink_speed:
  137. - void **cursor_set_blink_speed** **(** :ref:`float<class_float>` blink_speed **)**
  138. Set the line edit caret blink speed. Cannot be less then or equal to 0.
  139. .. _class_LineEdit_get_align:
  140. - :ref:`int<class_int>` **get_align** **(** **)** const
  141. Return the align mode of the ``LineEdit``.
  142. .. _class_LineEdit_get_cursor_position:
  143. - :ref:`int<class_int>` **get_cursor_position** **(** **)** const
  144. Returns the cursor position inside the ``LineEdit``.
  145. .. _class_LineEdit_get_expand_to_text_length:
  146. - :ref:`bool<class_bool>` **get_expand_to_text_length** **(** **)** const
  147. .. _class_LineEdit_get_max_length:
  148. - :ref:`int<class_int>` **get_max_length** **(** **)** const
  149. Return the maximum amount of characters the ``LineEdit`` can edit. If 0 is returned, no limit exists.
  150. .. _class_LineEdit_get_menu:
  151. - :ref:`PopupMenu<class_popupmenu>` **get_menu** **(** **)** const
  152. Returns the :ref:`PopupMenu<class_popupmenu>` of this ``LineEdit``. By default, this menu is displayed when right-clicking on the :ref:`LineEdit<class_lineedit>`.
  153. .. _class_LineEdit_get_placeholder:
  154. - :ref:`String<class_string>` **get_placeholder** **(** **)** const
  155. Return the placeholder text.
  156. .. _class_LineEdit_get_placeholder_alpha:
  157. - :ref:`float<class_float>` **get_placeholder_alpha** **(** **)** const
  158. Return transparency of the placeholder text.
  159. .. _class_LineEdit_get_text:
  160. - :ref:`String<class_string>` **get_text** **(** **)** const
  161. Return the text in the ``LineEdit``.
  162. .. _class_LineEdit_is_editable:
  163. - :ref:`bool<class_bool>` **is_editable** **(** **)** const
  164. Return the *editable* status of the ``LineEdit`` (see :ref:`set_editable<class_LineEdit_set_editable>`).
  165. .. _class_LineEdit_is_secret:
  166. - :ref:`bool<class_bool>` **is_secret** **(** **)** const
  167. Return the *secret* status of the ``LineEdit`` (see :ref:`set_secret<class_LineEdit_set_secret>`).
  168. .. _class_LineEdit_menu_option:
  169. - void **menu_option** **(** :ref:`int<class_int>` option **)**
  170. Executes a given action as defined in the MENU\_\* enum.
  171. .. _class_LineEdit_select:
  172. - void **select** **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)**
  173. Selects characters inside :ref:`LineEdit<class_lineedit>` between ``from`` and ``to``. By default ``from`` is at the beginning and ``to`` at the end.
  174. ::
  175. text = "Welcome"
  176. select() # Welcome
  177. select(4) # ome
  178. select(2, 5) # lco
  179. .. _class_LineEdit_select_all:
  180. - void **select_all** **(** **)**
  181. Selects the whole :ref:`String<class_string>`.
  182. .. _class_LineEdit_set_align:
  183. - void **set_align** **(** :ref:`int<class_int>` align **)**
  184. Set text alignment of the ``LineEdit``.
  185. .. _class_LineEdit_set_cursor_position:
  186. - void **set_cursor_position** **(** :ref:`int<class_int>` position **)**
  187. Sets the cursor position inside the ``LineEdit``. The text may scroll if needed.
  188. .. _class_LineEdit_set_editable:
  189. - void **set_editable** **(** :ref:`bool<class_bool>` enabled **)**
  190. Set the *editable* status of the ``LineEdit``. When disabled, existing text can't be modified and new text can't be added.
  191. .. _class_LineEdit_set_expand_to_text_length:
  192. - void **set_expand_to_text_length** **(** :ref:`bool<class_bool>` enabled **)**
  193. .. _class_LineEdit_set_max_length:
  194. - void **set_max_length** **(** :ref:`int<class_int>` chars **)**
  195. Set the maximum amount of characters the ``LineEdit`` can edit, and cropping existing text in case it exceeds that limit. Setting 0 removes the limit.
  196. .. _class_LineEdit_set_placeholder:
  197. - void **set_placeholder** **(** :ref:`String<class_string>` text **)**
  198. Set the placeholder text.
  199. .. _class_LineEdit_set_placeholder_alpha:
  200. - void **set_placeholder_alpha** **(** :ref:`float<class_float>` alpha **)**
  201. Set transparency of the placeholder text.
  202. .. _class_LineEdit_set_secret:
  203. - void **set_secret** **(** :ref:`bool<class_bool>` enabled **)**
  204. Set the *secret* status of the ``LineEdit``. When enabled, every character is displayed as "\*".
  205. .. _class_LineEdit_set_text:
  206. - void **set_text** **(** :ref:`String<class_string>` text **)**
  207. Set the text in the ``LineEdit``, clearing the existing one and the selection.