class_lineedit.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. Properties
  13. ----------
  14. +------------------------------------------+-----------------------------------------------------------------------------+
  15. | :ref:`Align<enum_LineEdit_Align>` | :ref:`align<class_LineEdit_property_align>` |
  16. +------------------------------------------+-----------------------------------------------------------------------------+
  17. | :ref:`bool<class_bool>` | :ref:`caret_blink<class_LineEdit_property_caret_blink>` |
  18. +------------------------------------------+-----------------------------------------------------------------------------+
  19. | :ref:`float<class_float>` | :ref:`caret_blink_speed<class_LineEdit_property_caret_blink_speed>` |
  20. +------------------------------------------+-----------------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`caret_position<class_LineEdit_property_caret_position>` |
  22. +------------------------------------------+-----------------------------------------------------------------------------+
  23. | :ref:`bool<class_bool>` | :ref:`clear_button_enabled<class_LineEdit_property_clear_button_enabled>` |
  24. +------------------------------------------+-----------------------------------------------------------------------------+
  25. | :ref:`bool<class_bool>` | :ref:`context_menu_enabled<class_LineEdit_property_context_menu_enabled>` |
  26. +------------------------------------------+-----------------------------------------------------------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`editable<class_LineEdit_property_editable>` |
  28. +------------------------------------------+-----------------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`expand_to_text_length<class_LineEdit_property_expand_to_text_length>` |
  30. +------------------------------------------+-----------------------------------------------------------------------------+
  31. | :ref:`FocusMode<enum_Control_FocusMode>` | :ref:`focus_mode<class_LineEdit_property_focus_mode>` |
  32. +------------------------------------------+-----------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`max_length<class_LineEdit_property_max_length>` |
  34. +------------------------------------------+-----------------------------------------------------------------------------+
  35. | :ref:`float<class_float>` | :ref:`placeholder_alpha<class_LineEdit_property_placeholder_alpha>` |
  36. +------------------------------------------+-----------------------------------------------------------------------------+
  37. | :ref:`String<class_String>` | :ref:`placeholder_text<class_LineEdit_property_placeholder_text>` |
  38. +------------------------------------------+-----------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`secret<class_LineEdit_property_secret>` |
  40. +------------------------------------------+-----------------------------------------------------------------------------+
  41. | :ref:`String<class_String>` | :ref:`secret_character<class_LineEdit_property_secret_character>` |
  42. +------------------------------------------+-----------------------------------------------------------------------------+
  43. | :ref:`String<class_String>` | :ref:`text<class_LineEdit_property_text>` |
  44. +------------------------------------------+-----------------------------------------------------------------------------+
  45. Methods
  46. -------
  47. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`append_at_cursor<class_LineEdit_method_append_at_cursor>` **(** :ref:`String<class_String>` text **)** |
  49. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`clear<class_LineEdit_method_clear>` **(** **)** |
  51. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`deselect<class_LineEdit_method_deselect>` **(** **)** |
  53. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_menu<class_LineEdit_method_get_menu>` **(** **)** const |
  55. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`menu_option<class_LineEdit_method_menu_option>` **(** :ref:`int<class_int>` option **)** |
  57. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`select<class_LineEdit_method_select>` **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)** |
  59. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`select_all<class_LineEdit_method_select_all>` **(** **)** |
  61. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  62. Theme Properties
  63. ----------------
  64. +---------------------------------+----------------------------+
  65. | :ref:`Texture<class_Texture>` | clear |
  66. +---------------------------------+----------------------------+
  67. | :ref:`Color<class_Color>` | clear_button_color |
  68. +---------------------------------+----------------------------+
  69. | :ref:`Color<class_Color>` | clear_button_color_pressed |
  70. +---------------------------------+----------------------------+
  71. | :ref:`Color<class_Color>` | cursor_color |
  72. +---------------------------------+----------------------------+
  73. | :ref:`StyleBox<class_StyleBox>` | focus |
  74. +---------------------------------+----------------------------+
  75. | :ref:`Font<class_Font>` | font |
  76. +---------------------------------+----------------------------+
  77. | :ref:`Color<class_Color>` | font_color |
  78. +---------------------------------+----------------------------+
  79. | :ref:`Color<class_Color>` | font_color_selected |
  80. +---------------------------------+----------------------------+
  81. | :ref:`int<class_int>` | minimum_spaces |
  82. +---------------------------------+----------------------------+
  83. | :ref:`StyleBox<class_StyleBox>` | normal |
  84. +---------------------------------+----------------------------+
  85. | :ref:`StyleBox<class_StyleBox>` | read_only |
  86. +---------------------------------+----------------------------+
  87. | :ref:`Color<class_Color>` | selection_color |
  88. +---------------------------------+----------------------------+
  89. Signals
  90. -------
  91. .. _class_LineEdit_signal_text_changed:
  92. - **text_changed** **(** :ref:`String<class_String>` new_text **)**
  93. Emitted when the text changes.
  94. .. _class_LineEdit_signal_text_entered:
  95. - **text_entered** **(** :ref:`String<class_String>` new_text **)**
  96. Emitted when the user presses :ref:`@GlobalScope.KEY_ENTER<class_@GlobalScope_constant_KEY_ENTER>` on the ``LineEdit``.
  97. Enumerations
  98. ------------
  99. .. _enum_LineEdit_Align:
  100. .. _class_LineEdit_constant_ALIGN_LEFT:
  101. .. _class_LineEdit_constant_ALIGN_CENTER:
  102. .. _class_LineEdit_constant_ALIGN_RIGHT:
  103. .. _class_LineEdit_constant_ALIGN_FILL:
  104. enum **Align**:
  105. - **ALIGN_LEFT** = **0** --- Aligns the text on the left hand side of the ``LineEdit``.
  106. - **ALIGN_CENTER** = **1** --- Centers the text in the middle of the ``LineEdit``.
  107. - **ALIGN_RIGHT** = **2** --- Aligns the text on the right hand side of the ``LineEdit``.
  108. - **ALIGN_FILL** = **3** --- Stretches whitespaces to fit the ``LineEdit``'s width.
  109. .. _enum_LineEdit_MenuItems:
  110. .. _class_LineEdit_constant_MENU_CUT:
  111. .. _class_LineEdit_constant_MENU_COPY:
  112. .. _class_LineEdit_constant_MENU_PASTE:
  113. .. _class_LineEdit_constant_MENU_CLEAR:
  114. .. _class_LineEdit_constant_MENU_SELECT_ALL:
  115. .. _class_LineEdit_constant_MENU_UNDO:
  116. .. _class_LineEdit_constant_MENU_REDO:
  117. .. _class_LineEdit_constant_MENU_MAX:
  118. enum **MenuItems**:
  119. - **MENU_CUT** = **0** --- Cuts (copies and clears) the selected text.
  120. - **MENU_COPY** = **1** --- Copies the selected text.
  121. - **MENU_PASTE** = **2** --- Pastes the clipboard text over the selected text (or at the cursor's position).
  122. - **MENU_CLEAR** = **3** --- Erases the whole ``LineEdit`` text.
  123. - **MENU_SELECT_ALL** = **4** --- Selects the whole ``LineEdit`` text.
  124. - **MENU_UNDO** = **5** --- Undoes the previous action.
  125. - **MENU_REDO** = **6** --- Reverse the last undo action.
  126. - **MENU_MAX** = **7**
  127. Description
  128. -----------
  129. LineEdit provides a single-line string editor, used for text fields. It features many built-in shortcuts which will always be available:
  130. - Ctrl + C: Copy
  131. - Ctrl + X: Cut
  132. - Ctrl + V or Ctrl + Y: Paste/"yank"
  133. - Ctrl + Z: Undo
  134. - Ctrl + Shift + Z: Redo
  135. - Ctrl + U: Delete text from the cursor position to the beginning of the line
  136. - Ctrl + K: Delete text from the cursor position to the end of the line
  137. - Ctrl + A: Select all text
  138. - Up/Down arrow: Move the cursor to the beginning/end of the line
  139. Property Descriptions
  140. ---------------------
  141. .. _class_LineEdit_property_align:
  142. - :ref:`Align<enum_LineEdit_Align>` **align**
  143. +----------+------------------+
  144. | *Setter* | set_align(value) |
  145. +----------+------------------+
  146. | *Getter* | get_align() |
  147. +----------+------------------+
  148. Text alignment as defined in the ALIGN\_\* enum.
  149. .. _class_LineEdit_property_caret_blink:
  150. - :ref:`bool<class_bool>` **caret_blink**
  151. +----------+---------------------------------+
  152. | *Setter* | cursor_set_blink_enabled(value) |
  153. +----------+---------------------------------+
  154. | *Getter* | cursor_get_blink_enabled() |
  155. +----------+---------------------------------+
  156. If ``true``, the caret (visual cursor) blinks.
  157. .. _class_LineEdit_property_caret_blink_speed:
  158. - :ref:`float<class_float>` **caret_blink_speed**
  159. +----------+-------------------------------+
  160. | *Setter* | cursor_set_blink_speed(value) |
  161. +----------+-------------------------------+
  162. | *Getter* | cursor_get_blink_speed() |
  163. +----------+-------------------------------+
  164. Duration (in seconds) of a caret's blinking cycle.
  165. .. _class_LineEdit_property_caret_position:
  166. - :ref:`int<class_int>` **caret_position**
  167. +----------+----------------------------+
  168. | *Setter* | set_cursor_position(value) |
  169. +----------+----------------------------+
  170. | *Getter* | get_cursor_position() |
  171. +----------+----------------------------+
  172. The cursor's position inside the ``LineEdit``. When set, the text may scroll to accommodate it.
  173. .. _class_LineEdit_property_clear_button_enabled:
  174. - :ref:`bool<class_bool>` **clear_button_enabled**
  175. +----------+---------------------------------+
  176. | *Setter* | set_clear_button_enabled(value) |
  177. +----------+---------------------------------+
  178. | *Getter* | is_clear_button_enabled() |
  179. +----------+---------------------------------+
  180. If ``true``, the ``LineEdit`` will show a clear button if ``text`` is not empty.
  181. .. _class_LineEdit_property_context_menu_enabled:
  182. - :ref:`bool<class_bool>` **context_menu_enabled**
  183. +----------+---------------------------------+
  184. | *Setter* | set_context_menu_enabled(value) |
  185. +----------+---------------------------------+
  186. | *Getter* | is_context_menu_enabled() |
  187. +----------+---------------------------------+
  188. If ``true``, the context menu will appear when right clicked.
  189. .. _class_LineEdit_property_editable:
  190. - :ref:`bool<class_bool>` **editable**
  191. +----------+---------------------+
  192. | *Setter* | set_editable(value) |
  193. +----------+---------------------+
  194. | *Getter* | is_editable() |
  195. +----------+---------------------+
  196. If ``false``, existing text cannot be modified and new text cannot be added.
  197. .. _class_LineEdit_property_expand_to_text_length:
  198. - :ref:`bool<class_bool>` **expand_to_text_length**
  199. +----------+----------------------------------+
  200. | *Setter* | set_expand_to_text_length(value) |
  201. +----------+----------------------------------+
  202. | *Getter* | get_expand_to_text_length() |
  203. +----------+----------------------------------+
  204. If ``true``, the ``LineEdit`` width will increase to stay longer than the :ref:`text<class_LineEdit_property_text>`. It will **not** compress if the :ref:`text<class_LineEdit_property_text>` is shortened.
  205. .. _class_LineEdit_property_focus_mode:
  206. - :ref:`FocusMode<enum_Control_FocusMode>` **focus_mode**
  207. +----------+-----------------------+
  208. | *Setter* | set_focus_mode(value) |
  209. +----------+-----------------------+
  210. | *Getter* | get_focus_mode() |
  211. +----------+-----------------------+
  212. Defines how the ``LineEdit`` can grab focus (Keyboard and mouse, only keyboard, or none). See :ref:`FocusMode<enum_Control_FocusMode>` in :ref:`Control<class_Control>` for details.
  213. .. _class_LineEdit_property_max_length:
  214. - :ref:`int<class_int>` **max_length**
  215. +----------+-----------------------+
  216. | *Setter* | set_max_length(value) |
  217. +----------+-----------------------+
  218. | *Getter* | get_max_length() |
  219. +----------+-----------------------+
  220. Maximum amount of characters that can be entered inside the ``LineEdit``. If ``0``, there is no limit.
  221. .. _class_LineEdit_property_placeholder_alpha:
  222. - :ref:`float<class_float>` **placeholder_alpha**
  223. +----------+------------------------------+
  224. | *Setter* | set_placeholder_alpha(value) |
  225. +----------+------------------------------+
  226. | *Getter* | get_placeholder_alpha() |
  227. +----------+------------------------------+
  228. Opacity of the :ref:`placeholder_text<class_LineEdit_property_placeholder_text>`. From ``0`` to ``1``.
  229. .. _class_LineEdit_property_placeholder_text:
  230. - :ref:`String<class_String>` **placeholder_text**
  231. +----------+------------------------+
  232. | *Setter* | set_placeholder(value) |
  233. +----------+------------------------+
  234. | *Getter* | get_placeholder() |
  235. +----------+------------------------+
  236. Text shown when the ``LineEdit`` is empty. It is **not** the ``LineEdit``'s default value (see :ref:`text<class_LineEdit_property_text>`).
  237. .. _class_LineEdit_property_secret:
  238. - :ref:`bool<class_bool>` **secret**
  239. +----------+-------------------+
  240. | *Setter* | set_secret(value) |
  241. +----------+-------------------+
  242. | *Getter* | is_secret() |
  243. +----------+-------------------+
  244. If ``true``, every character is replaced with the secret character (see :ref:`secret_character<class_LineEdit_property_secret_character>`).
  245. .. _class_LineEdit_property_secret_character:
  246. - :ref:`String<class_String>` **secret_character**
  247. +----------+-----------------------------+
  248. | *Setter* | set_secret_character(value) |
  249. +----------+-----------------------------+
  250. | *Getter* | get_secret_character() |
  251. +----------+-----------------------------+
  252. The character to use to mask secret input (defaults to "\*"). Only a single character can be used as the secret character.
  253. .. _class_LineEdit_property_text:
  254. - :ref:`String<class_String>` **text**
  255. +----------+-----------------+
  256. | *Setter* | set_text(value) |
  257. +----------+-----------------+
  258. | *Getter* | get_text() |
  259. +----------+-----------------+
  260. String value of the ``LineEdit``.
  261. Method Descriptions
  262. -------------------
  263. .. _class_LineEdit_method_append_at_cursor:
  264. - void **append_at_cursor** **(** :ref:`String<class_String>` text **)**
  265. Adds ``text`` after the cursor. If the resulting value is longer than :ref:`max_length<class_LineEdit_property_max_length>`, nothing happens.
  266. .. _class_LineEdit_method_clear:
  267. - void **clear** **(** **)**
  268. Erases the ``LineEdit`` text.
  269. .. _class_LineEdit_method_deselect:
  270. - void **deselect** **(** **)**
  271. Clears the current selection.
  272. .. _class_LineEdit_method_get_menu:
  273. - :ref:`PopupMenu<class_PopupMenu>` **get_menu** **(** **)** const
  274. Returns the :ref:`PopupMenu<class_PopupMenu>` of this ``LineEdit``. By default, this menu is displayed when right-clicking on the ``LineEdit``.
  275. .. _class_LineEdit_method_menu_option:
  276. - void **menu_option** **(** :ref:`int<class_int>` option **)**
  277. Executes a given action as defined in the MENU\_\* enum.
  278. .. _class_LineEdit_method_select:
  279. - void **select** **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)**
  280. Selects characters inside ``LineEdit`` between ``from`` and ``to``. By default ``from`` is at the beginning and ``to`` at the end.
  281. ::
  282. text = "Welcome"
  283. select() # Welcome
  284. select(4) # ome
  285. select(2, 5) # lco
  286. .. _class_LineEdit_method_select_all:
  287. - void **select_all** **(** **)**
  288. Selects the whole :ref:`String<class_String>`.