class_lineedit.rst 20 KB

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