class_lineedit.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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_align>` |
  16. +------------------------------------------+--------------------------------------------------------------------+
  17. | :ref:`bool<class_bool>` | :ref:`caret_blink<class_LineEdit_caret_blink>` |
  18. +------------------------------------------+--------------------------------------------------------------------+
  19. | :ref:`float<class_float>` | :ref:`caret_blink_speed<class_LineEdit_caret_blink_speed>` |
  20. +------------------------------------------+--------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`caret_position<class_LineEdit_caret_position>` |
  22. +------------------------------------------+--------------------------------------------------------------------+
  23. | :ref:`bool<class_bool>` | :ref:`clear_button_enabled<class_LineEdit_clear_button_enabled>` |
  24. +------------------------------------------+--------------------------------------------------------------------+
  25. | :ref:`bool<class_bool>` | :ref:`context_menu_enabled<class_LineEdit_context_menu_enabled>` |
  26. +------------------------------------------+--------------------------------------------------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`editable<class_LineEdit_editable>` |
  28. +------------------------------------------+--------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`expand_to_text_length<class_LineEdit_expand_to_text_length>` |
  30. +------------------------------------------+--------------------------------------------------------------------+
  31. | :ref:`FocusMode<enum_Control_FocusMode>` | :ref:`focus_mode<class_LineEdit_focus_mode>` |
  32. +------------------------------------------+--------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`max_length<class_LineEdit_max_length>` |
  34. +------------------------------------------+--------------------------------------------------------------------+
  35. | :ref:`float<class_float>` | :ref:`placeholder_alpha<class_LineEdit_placeholder_alpha>` |
  36. +------------------------------------------+--------------------------------------------------------------------+
  37. | :ref:`String<class_String>` | :ref:`placeholder_text<class_LineEdit_placeholder_text>` |
  38. +------------------------------------------+--------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`secret<class_LineEdit_secret>` |
  40. +------------------------------------------+--------------------------------------------------------------------+
  41. | :ref:`String<class_String>` | :ref:`secret_character<class_LineEdit_secret_character>` |
  42. +------------------------------------------+--------------------------------------------------------------------+
  43. | :ref:`String<class_String>` | :ref:`text<class_LineEdit_text>` |
  44. +------------------------------------------+--------------------------------------------------------------------+
  45. Methods
  46. -------
  47. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`append_at_cursor<class_LineEdit_append_at_cursor>` **(** :ref:`String<class_String>` text **)** |
  49. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`clear<class_LineEdit_clear>` **(** **)** |
  51. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`deselect<class_LineEdit_deselect>` **(** **)** |
  53. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  54. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_menu<class_LineEdit_get_menu>` **(** **)** const |
  55. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`menu_option<class_LineEdit_menu_option>` **(** :ref:`int<class_int>` option **)** |
  57. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`select<class_LineEdit_select>` **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)** |
  59. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`select_all<class_LineEdit_select_all>` **(** **)** |
  61. +------------------------------------+------------------------------------------------------------------------------------------------------------+
  62. Theme Properties
  63. ----------------
  64. +---------------------------------+------------------------------------------------------------------------------+
  65. | :ref:`Texture<class_Texture>` | :ref:`clear<class_LineEdit_clear>` |
  66. +---------------------------------+------------------------------------------------------------------------------+
  67. | :ref:`Color<class_Color>` | :ref:`clear_button_color<class_LineEdit_clear_button_color>` |
  68. +---------------------------------+------------------------------------------------------------------------------+
  69. | :ref:`Color<class_Color>` | :ref:`clear_button_color_pressed<class_LineEdit_clear_button_color_pressed>` |
  70. +---------------------------------+------------------------------------------------------------------------------+
  71. | :ref:`Color<class_Color>` | :ref:`cursor_color<class_LineEdit_cursor_color>` |
  72. +---------------------------------+------------------------------------------------------------------------------+
  73. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_LineEdit_focus>` |
  74. +---------------------------------+------------------------------------------------------------------------------+
  75. | :ref:`Font<class_Font>` | :ref:`font<class_LineEdit_font>` |
  76. +---------------------------------+------------------------------------------------------------------------------+
  77. | :ref:`Color<class_Color>` | :ref:`font_color<class_LineEdit_font_color>` |
  78. +---------------------------------+------------------------------------------------------------------------------+
  79. | :ref:`Color<class_Color>` | :ref:`font_color_selected<class_LineEdit_font_color_selected>` |
  80. +---------------------------------+------------------------------------------------------------------------------+
  81. | :ref:`int<class_int>` | :ref:`minimum_spaces<class_LineEdit_minimum_spaces>` |
  82. +---------------------------------+------------------------------------------------------------------------------+
  83. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_LineEdit_normal>` |
  84. +---------------------------------+------------------------------------------------------------------------------+
  85. | :ref:`StyleBox<class_StyleBox>` | :ref:`read_only<class_LineEdit_read_only>` |
  86. +---------------------------------+------------------------------------------------------------------------------+
  87. | :ref:`Color<class_Color>` | :ref:`selection_color<class_LineEdit_selection_color>` |
  88. +---------------------------------+------------------------------------------------------------------------------+
  89. Signals
  90. -------
  91. .. _class_LineEdit_text_changed:
  92. - **text_changed** **(** :ref:`String<class_String>` new_text **)**
  93. Emitted when the text changes.
  94. .. _class_LineEdit_text_entered:
  95. - **text_entered** **(** :ref:`String<class_String>` new_text **)**
  96. Emitted when the user presses KEY_ENTER on the ``LineEdit``.
  97. Enumerations
  98. ------------
  99. .. _enum_LineEdit_Align:
  100. enum **Align**:
  101. - **ALIGN_LEFT** = **0** --- Aligns the text on the left hand side of the :ref:`LineEdit<class_LineEdit>`.
  102. - **ALIGN_CENTER** = **1** --- Centers the text in the middle of the :ref:`LineEdit<class_LineEdit>`.
  103. - **ALIGN_RIGHT** = **2** --- Aligns the text on the right hand side of the :ref:`LineEdit<class_LineEdit>`.
  104. - **ALIGN_FILL** = **3** --- Stretches whitespaces to fit the :ref:`LineEdit<class_LineEdit>`'s width.
  105. .. _enum_LineEdit_MenuItems:
  106. enum **MenuItems**:
  107. - **MENU_CUT** = **0** --- Cuts (Copies and clears) the selected text.
  108. - **MENU_COPY** = **1** --- Copies the selected text.
  109. - **MENU_PASTE** = **2** --- Pastes the clipboard text over the selected text (or at the cursor's position).
  110. - **MENU_CLEAR** = **3** --- Erases the whole Linedit text.
  111. - **MENU_SELECT_ALL** = **4** --- Selects the whole Linedit text.
  112. - **MENU_UNDO** = **5** --- Undoes the previous action.
  113. - **MENU_REDO** = **6** --- Reverse the last undo action.
  114. - **MENU_MAX** = **7**
  115. Description
  116. -----------
  117. LineEdit provides a single line string editor, used for text fields.
  118. Property Descriptions
  119. ---------------------
  120. .. _class_LineEdit_align:
  121. - :ref:`Align<enum_LineEdit_Align>` **align**
  122. +----------+------------------+
  123. | *Setter* | set_align(value) |
  124. +----------+------------------+
  125. | *Getter* | get_align() |
  126. +----------+------------------+
  127. Text alignment as defined in the ALIGN\_\* enum.
  128. .. _class_LineEdit_caret_blink:
  129. - :ref:`bool<class_bool>` **caret_blink**
  130. +----------+---------------------------------+
  131. | *Setter* | cursor_set_blink_enabled(value) |
  132. +----------+---------------------------------+
  133. | *Getter* | cursor_get_blink_enabled() |
  134. +----------+---------------------------------+
  135. If ``true`` the caret (visual cursor) blinks.
  136. .. _class_LineEdit_caret_blink_speed:
  137. - :ref:`float<class_float>` **caret_blink_speed**
  138. +----------+-------------------------------+
  139. | *Setter* | cursor_set_blink_speed(value) |
  140. +----------+-------------------------------+
  141. | *Getter* | cursor_get_blink_speed() |
  142. +----------+-------------------------------+
  143. Duration (in seconds) of a caret's blinking cycle.
  144. .. _class_LineEdit_caret_position:
  145. - :ref:`int<class_int>` **caret_position**
  146. +----------+----------------------------+
  147. | *Setter* | set_cursor_position(value) |
  148. +----------+----------------------------+
  149. | *Getter* | get_cursor_position() |
  150. +----------+----------------------------+
  151. The cursor's position inside the ``LineEdit``. When set, the text may scroll to accommodate it.
  152. .. _class_LineEdit_clear_button_enabled:
  153. - :ref:`bool<class_bool>` **clear_button_enabled**
  154. +----------+---------------------------------+
  155. | *Setter* | set_clear_button_enabled(value) |
  156. +----------+---------------------------------+
  157. | *Getter* | is_clear_button_enabled() |
  158. +----------+---------------------------------+
  159. If ``true`` the ``LineEdit`` will show a clear button if ``text`` is not empty.
  160. .. _class_LineEdit_context_menu_enabled:
  161. - :ref:`bool<class_bool>` **context_menu_enabled**
  162. +----------+---------------------------------+
  163. | *Setter* | set_context_menu_enabled(value) |
  164. +----------+---------------------------------+
  165. | *Getter* | is_context_menu_enabled() |
  166. +----------+---------------------------------+
  167. If ``true`` the context menu will appear when right clicked.
  168. .. _class_LineEdit_editable:
  169. - :ref:`bool<class_bool>` **editable**
  170. +----------+---------------------+
  171. | *Setter* | set_editable(value) |
  172. +----------+---------------------+
  173. | *Getter* | is_editable() |
  174. +----------+---------------------+
  175. If ``false`` existing text cannot be modified and new text cannot be added.
  176. .. _class_LineEdit_expand_to_text_length:
  177. - :ref:`bool<class_bool>` **expand_to_text_length**
  178. +----------+----------------------------------+
  179. | *Setter* | set_expand_to_text_length(value) |
  180. +----------+----------------------------------+
  181. | *Getter* | get_expand_to_text_length() |
  182. +----------+----------------------------------+
  183. 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.
  184. .. _class_LineEdit_focus_mode:
  185. - :ref:`FocusMode<enum_Control_FocusMode>` **focus_mode**
  186. +----------+-----------------------+
  187. | *Setter* | set_focus_mode(value) |
  188. +----------+-----------------------+
  189. | *Getter* | get_focus_mode() |
  190. +----------+-----------------------+
  191. 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.
  192. .. _class_LineEdit_max_length:
  193. - :ref:`int<class_int>` **max_length**
  194. +----------+-----------------------+
  195. | *Setter* | set_max_length(value) |
  196. +----------+-----------------------+
  197. | *Getter* | get_max_length() |
  198. +----------+-----------------------+
  199. Maximum amount of characters that can be entered inside the :ref:`LineEdit<class_LineEdit>`. If ``0``, there is no limit.
  200. .. _class_LineEdit_placeholder_alpha:
  201. - :ref:`float<class_float>` **placeholder_alpha**
  202. +----------+------------------------------+
  203. | *Setter* | set_placeholder_alpha(value) |
  204. +----------+------------------------------+
  205. | *Getter* | get_placeholder_alpha() |
  206. +----------+------------------------------+
  207. Opacity of the :ref:`placeholder_text<class_LineEdit_placeholder_text>`. From ``0`` to ``1``.
  208. .. _class_LineEdit_placeholder_text:
  209. - :ref:`String<class_String>` **placeholder_text**
  210. +----------+------------------------+
  211. | *Setter* | set_placeholder(value) |
  212. +----------+------------------------+
  213. | *Getter* | get_placeholder() |
  214. +----------+------------------------+
  215. 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>`).
  216. .. _class_LineEdit_secret:
  217. - :ref:`bool<class_bool>` **secret**
  218. +----------+-------------------+
  219. | *Setter* | set_secret(value) |
  220. +----------+-------------------+
  221. | *Getter* | is_secret() |
  222. +----------+-------------------+
  223. If ``true``, every character is replaced with the secret character (see :ref:`secret_character<class_LineEdit_secret_character>`).
  224. .. _class_LineEdit_secret_character:
  225. - :ref:`String<class_String>` **secret_character**
  226. +----------+-----------------------------+
  227. | *Setter* | set_secret_character(value) |
  228. +----------+-----------------------------+
  229. | *Getter* | get_secret_character() |
  230. +----------+-----------------------------+
  231. The character to use to mask secret input (defaults to "\*"). Only a single character can be used as the secret character.
  232. .. _class_LineEdit_text:
  233. - :ref:`String<class_String>` **text**
  234. +----------+-----------------+
  235. | *Setter* | set_text(value) |
  236. +----------+-----------------+
  237. | *Getter* | get_text() |
  238. +----------+-----------------+
  239. String value of the :ref:`LineEdit<class_LineEdit>`.
  240. Method Descriptions
  241. -------------------
  242. .. _class_LineEdit_append_at_cursor:
  243. - void **append_at_cursor** **(** :ref:`String<class_String>` text **)**
  244. Adds ``text`` after the cursor. If the resulting value is longer than :ref:`max_length<class_LineEdit_max_length>`, nothing happens.
  245. .. _class_LineEdit_clear:
  246. - void **clear** **(** **)**
  247. Erases the :ref:`LineEdit<class_LineEdit>` text.
  248. .. _class_LineEdit_deselect:
  249. - void **deselect** **(** **)**
  250. Clears the current selection.
  251. .. _class_LineEdit_get_menu:
  252. - :ref:`PopupMenu<class_PopupMenu>` **get_menu** **(** **)** const
  253. Returns the :ref:`PopupMenu<class_PopupMenu>` of this ``LineEdit``. By default, this menu is displayed when right-clicking on the :ref:`LineEdit<class_LineEdit>`.
  254. .. _class_LineEdit_menu_option:
  255. - void **menu_option** **(** :ref:`int<class_int>` option **)**
  256. Executes a given action as defined in the MENU\_\* enum.
  257. .. _class_LineEdit_select:
  258. - void **select** **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)**
  259. Selects characters inside :ref:`LineEdit<class_LineEdit>` between ``from`` and ``to``. By default ``from`` is at the beginning and ``to`` at the end.
  260. ::
  261. text = "Welcome"
  262. select() # Welcome
  263. select(4) # ome
  264. select(2, 5) # lco
  265. .. _class_LineEdit_select_all:
  266. - void **select_all** **(** **)**
  267. Selects the whole :ref:`String<class_String>`.