class_label.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Label.xml.
  6. .. _class_Label:
  7. Label
  8. =====
  9. **Inherits:** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. Displays plain text in a line or wrapped inside a rectangle. For formatted text, use :ref:`RichTextLabel<class_RichTextLabel>`.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Label displays plain text on the screen. It gives you control over the horizontal and vertical alignment and can wrap the text inside the node's bounding rectangle. It doesn't support bold, italics, or other formatting. For that, use :ref:`RichTextLabel<class_RichTextLabel>` instead.
  15. \ **Note:** Contrarily to most other :ref:`Control<class_Control>`\ s, Label's :ref:`Control.mouse_filter<class_Control_property_mouse_filter>` defaults to :ref:`Control.MOUSE_FILTER_IGNORE<class_Control_constant_MOUSE_FILTER_IGNORE>` (i.e. it doesn't react to mouse input events). This implies that a label won't display any configured :ref:`Control.hint_tooltip<class_Control_property_hint_tooltip>`, unless you change its mouse filter.
  16. \ **Note:** Unicode characters after ``0xffff`` (such as most emoji) are *not* supported on Windows. They will display as unknown characters instead. This will be resolved in Godot 4.0.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`__
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  27. | :ref:`Align<enum_Label_Align>` | :ref:`align<class_Label_property_align>` | ``0`` |
  28. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`autowrap<class_Label_property_autowrap>` | ``false`` |
  30. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`clip_text<class_Label_property_clip_text>` | ``false`` |
  32. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`lines_skipped<class_Label_property_lines_skipped>` | ``0`` |
  34. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`max_lines_visible<class_Label_property_max_lines_visible>` | ``-1`` |
  36. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  37. | :ref:`MouseFilter<enum_Control_MouseFilter>` | mouse_filter | ``2`` (overrides :ref:`Control<class_Control_property_mouse_filter>`) |
  38. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`percent_visible<class_Label_property_percent_visible>` | ``1.0`` |
  40. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | size_flags_vertical | ``4`` (overrides :ref:`Control<class_Control_property_size_flags_vertical>`) |
  42. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  43. | :ref:`String<class_String>` | :ref:`text<class_Label_property_text>` | ``""`` |
  44. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`uppercase<class_Label_property_uppercase>` | ``false`` |
  46. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  47. | :ref:`VAlign<enum_Label_VAlign>` | :ref:`valign<class_Label_property_valign>` | ``0`` |
  48. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  49. | :ref:`int<class_int>` | :ref:`visible_characters<class_Label_property_visible_characters>` | ``-1`` |
  50. +----------------------------------------------+--------------------------------------------------------------------+------------------------------------------------------------------------------+
  51. .. rst-class:: classref-reftable-group
  52. Methods
  53. -------
  54. .. table::
  55. :widths: auto
  56. +-----------------------+----------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_line_count<class_Label_method_get_line_count>` **(** **)** |const| |
  58. +-----------------------+----------------------------------------------------------------------------------------------------+
  59. | :ref:`int<class_int>` | :ref:`get_line_height<class_Label_method_get_line_height>` **(** **)** |const| |
  60. +-----------------------+----------------------------------------------------------------------------------------------------+
  61. | :ref:`int<class_int>` | :ref:`get_total_character_count<class_Label_method_get_total_character_count>` **(** **)** |const| |
  62. +-----------------------+----------------------------------------------------------------------------------------------------+
  63. | :ref:`int<class_int>` | :ref:`get_visible_line_count<class_Label_method_get_visible_line_count>` **(** **)** |const| |
  64. +-----------------------+----------------------------------------------------------------------------------------------------+
  65. .. rst-class:: classref-reftable-group
  66. Theme Properties
  67. ----------------
  68. .. table::
  69. :widths: auto
  70. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  71. | :ref:`Color<class_Color>` | :ref:`font_color<class_Label_theme_color_font_color>` | ``Color( 1, 1, 1, 1 )`` |
  72. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  73. | :ref:`Color<class_Color>` | :ref:`font_color_shadow<class_Label_theme_color_font_color_shadow>` | ``Color( 0, 0, 0, 0 )`` |
  74. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  75. | :ref:`Color<class_Color>` | :ref:`font_outline_modulate<class_Label_theme_color_font_outline_modulate>` | ``Color( 1, 1, 1, 1 )`` |
  76. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  77. | :ref:`int<class_int>` | :ref:`line_spacing<class_Label_theme_constant_line_spacing>` | ``3`` |
  78. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  79. | :ref:`int<class_int>` | :ref:`shadow_as_outline<class_Label_theme_constant_shadow_as_outline>` | ``0`` |
  80. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  81. | :ref:`int<class_int>` | :ref:`shadow_offset_x<class_Label_theme_constant_shadow_offset_x>` | ``1`` |
  82. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  83. | :ref:`int<class_int>` | :ref:`shadow_offset_y<class_Label_theme_constant_shadow_offset_y>` | ``1`` |
  84. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  85. | :ref:`Font<class_Font>` | :ref:`font<class_Label_theme_font_font>` | |
  86. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  87. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_Label_theme_style_normal>` | |
  88. +---------------------------------+-----------------------------------------------------------------------------+-------------------------+
  89. .. rst-class:: classref-section-separator
  90. ----
  91. .. rst-class:: classref-descriptions-group
  92. Enumerations
  93. ------------
  94. .. _enum_Label_Align:
  95. .. rst-class:: classref-enumeration
  96. enum **Align**:
  97. .. _class_Label_constant_ALIGN_LEFT:
  98. .. rst-class:: classref-enumeration-constant
  99. :ref:`Align<enum_Label_Align>` **ALIGN_LEFT** = ``0``
  100. Align rows to the left (default).
  101. .. _class_Label_constant_ALIGN_CENTER:
  102. .. rst-class:: classref-enumeration-constant
  103. :ref:`Align<enum_Label_Align>` **ALIGN_CENTER** = ``1``
  104. Align rows centered.
  105. .. _class_Label_constant_ALIGN_RIGHT:
  106. .. rst-class:: classref-enumeration-constant
  107. :ref:`Align<enum_Label_Align>` **ALIGN_RIGHT** = ``2``
  108. Align rows to the right.
  109. .. _class_Label_constant_ALIGN_FILL:
  110. .. rst-class:: classref-enumeration-constant
  111. :ref:`Align<enum_Label_Align>` **ALIGN_FILL** = ``3``
  112. Expand row whitespaces to fit the width.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _enum_Label_VAlign:
  116. .. rst-class:: classref-enumeration
  117. enum **VAlign**:
  118. .. _class_Label_constant_VALIGN_TOP:
  119. .. rst-class:: classref-enumeration-constant
  120. :ref:`VAlign<enum_Label_VAlign>` **VALIGN_TOP** = ``0``
  121. Align the whole text to the top.
  122. .. _class_Label_constant_VALIGN_CENTER:
  123. .. rst-class:: classref-enumeration-constant
  124. :ref:`VAlign<enum_Label_VAlign>` **VALIGN_CENTER** = ``1``
  125. Align the whole text to the center.
  126. .. _class_Label_constant_VALIGN_BOTTOM:
  127. .. rst-class:: classref-enumeration-constant
  128. :ref:`VAlign<enum_Label_VAlign>` **VALIGN_BOTTOM** = ``2``
  129. Align the whole text to the bottom.
  130. .. _class_Label_constant_VALIGN_FILL:
  131. .. rst-class:: classref-enumeration-constant
  132. :ref:`VAlign<enum_Label_VAlign>` **VALIGN_FILL** = ``3``
  133. Align the whole text by spreading the rows.
  134. .. rst-class:: classref-section-separator
  135. ----
  136. .. rst-class:: classref-descriptions-group
  137. Property Descriptions
  138. ---------------------
  139. .. _class_Label_property_align:
  140. .. rst-class:: classref-property
  141. :ref:`Align<enum_Label_Align>` **align** = ``0``
  142. .. rst-class:: classref-property-setget
  143. - void **set_align** **(** :ref:`Align<enum_Label_Align>` value **)**
  144. - :ref:`Align<enum_Label_Align>` **get_align** **(** **)**
  145. Controls the text's horizontal align. Supports left, center, right, and fill, or justify. Set it to one of the :ref:`Align<enum_Label_Align>` constants.
  146. .. rst-class:: classref-item-separator
  147. ----
  148. .. _class_Label_property_autowrap:
  149. .. rst-class:: classref-property
  150. :ref:`bool<class_bool>` **autowrap** = ``false``
  151. .. rst-class:: classref-property-setget
  152. - void **set_autowrap** **(** :ref:`bool<class_bool>` value **)**
  153. - :ref:`bool<class_bool>` **has_autowrap** **(** **)**
  154. If ``true``, wraps the text inside the node's bounding rectangle. If you resize the node, it will change its height automatically to show all the text.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_Label_property_clip_text:
  158. .. rst-class:: classref-property
  159. :ref:`bool<class_bool>` **clip_text** = ``false``
  160. .. rst-class:: classref-property-setget
  161. - void **set_clip_text** **(** :ref:`bool<class_bool>` value **)**
  162. - :ref:`bool<class_bool>` **is_clipping_text** **(** **)**
  163. If ``true``, the Label only shows the text that fits inside its bounding rectangle and will clip text horizontally.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_Label_property_lines_skipped:
  167. .. rst-class:: classref-property
  168. :ref:`int<class_int>` **lines_skipped** = ``0``
  169. .. rst-class:: classref-property-setget
  170. - void **set_lines_skipped** **(** :ref:`int<class_int>` value **)**
  171. - :ref:`int<class_int>` **get_lines_skipped** **(** **)**
  172. The node ignores the first ``lines_skipped`` lines before it starts to display text.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_Label_property_max_lines_visible:
  176. .. rst-class:: classref-property
  177. :ref:`int<class_int>` **max_lines_visible** = ``-1``
  178. .. rst-class:: classref-property-setget
  179. - void **set_max_lines_visible** **(** :ref:`int<class_int>` value **)**
  180. - :ref:`int<class_int>` **get_max_lines_visible** **(** **)**
  181. Limits the lines of text the node shows on screen.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_Label_property_percent_visible:
  185. .. rst-class:: classref-property
  186. :ref:`float<class_float>` **percent_visible** = ``1.0``
  187. .. rst-class:: classref-property-setget
  188. - void **set_percent_visible** **(** :ref:`float<class_float>` value **)**
  189. - :ref:`float<class_float>` **get_percent_visible** **(** **)**
  190. Limits the amount of visible characters. If you set ``percent_visible`` to 0.5, only up to half of the text's characters will display on screen. Useful to animate the text in a dialog box.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_Label_property_text:
  194. .. rst-class:: classref-property
  195. :ref:`String<class_String>` **text** = ``""``
  196. .. rst-class:: classref-property-setget
  197. - void **set_text** **(** :ref:`String<class_String>` value **)**
  198. - :ref:`String<class_String>` **get_text** **(** **)**
  199. The text to display on screen.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_Label_property_uppercase:
  203. .. rst-class:: classref-property
  204. :ref:`bool<class_bool>` **uppercase** = ``false``
  205. .. rst-class:: classref-property-setget
  206. - void **set_uppercase** **(** :ref:`bool<class_bool>` value **)**
  207. - :ref:`bool<class_bool>` **is_uppercase** **(** **)**
  208. If ``true``, all the text displays as UPPERCASE.
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_Label_property_valign:
  212. .. rst-class:: classref-property
  213. :ref:`VAlign<enum_Label_VAlign>` **valign** = ``0``
  214. .. rst-class:: classref-property-setget
  215. - void **set_valign** **(** :ref:`VAlign<enum_Label_VAlign>` value **)**
  216. - :ref:`VAlign<enum_Label_VAlign>` **get_valign** **(** **)**
  217. Controls the text's vertical align. Supports top, center, bottom, and fill. Set it to one of the :ref:`VAlign<enum_Label_VAlign>` constants.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_Label_property_visible_characters:
  221. .. rst-class:: classref-property
  222. :ref:`int<class_int>` **visible_characters** = ``-1``
  223. .. rst-class:: classref-property-setget
  224. - void **set_visible_characters** **(** :ref:`int<class_int>` value **)**
  225. - :ref:`int<class_int>` **get_visible_characters** **(** **)**
  226. Restricts the number of characters to display. Set to -1 to disable.
  227. .. rst-class:: classref-section-separator
  228. ----
  229. .. rst-class:: classref-descriptions-group
  230. Method Descriptions
  231. -------------------
  232. .. _class_Label_method_get_line_count:
  233. .. rst-class:: classref-method
  234. :ref:`int<class_int>` **get_line_count** **(** **)** |const|
  235. Returns the amount of lines of text the Label has.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_Label_method_get_line_height:
  239. .. rst-class:: classref-method
  240. :ref:`int<class_int>` **get_line_height** **(** **)** |const|
  241. Returns the font size in pixels.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_Label_method_get_total_character_count:
  245. .. rst-class:: classref-method
  246. :ref:`int<class_int>` **get_total_character_count** **(** **)** |const|
  247. Returns the total number of printable characters in the text (excluding spaces and newlines).
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_Label_method_get_visible_line_count:
  251. .. rst-class:: classref-method
  252. :ref:`int<class_int>` **get_visible_line_count** **(** **)** |const|
  253. Returns the number of lines shown. Useful if the **Label**'s height cannot currently display all lines.
  254. .. rst-class:: classref-section-separator
  255. ----
  256. .. rst-class:: classref-descriptions-group
  257. Theme Property Descriptions
  258. ---------------------------
  259. .. _class_Label_theme_color_font_color:
  260. .. rst-class:: classref-themeproperty
  261. :ref:`Color<class_Color>` **font_color** = ``Color( 1, 1, 1, 1 )``
  262. Default text :ref:`Color<class_Color>` of the **Label**.
  263. .. rst-class:: classref-item-separator
  264. ----
  265. .. _class_Label_theme_color_font_color_shadow:
  266. .. rst-class:: classref-themeproperty
  267. :ref:`Color<class_Color>` **font_color_shadow** = ``Color( 0, 0, 0, 0 )``
  268. :ref:`Color<class_Color>` of the text's shadow effect.
  269. .. rst-class:: classref-item-separator
  270. ----
  271. .. _class_Label_theme_color_font_outline_modulate:
  272. .. rst-class:: classref-themeproperty
  273. :ref:`Color<class_Color>` **font_outline_modulate** = ``Color( 1, 1, 1, 1 )``
  274. The tint of :ref:`Font<class_Font>`'s outline. See :ref:`DynamicFont.outline_color<class_DynamicFont_property_outline_color>`.
  275. .. rst-class:: classref-item-separator
  276. ----
  277. .. _class_Label_theme_constant_line_spacing:
  278. .. rst-class:: classref-themeproperty
  279. :ref:`int<class_int>` **line_spacing** = ``3``
  280. Vertical space between lines in multiline **Label**.
  281. .. rst-class:: classref-item-separator
  282. ----
  283. .. _class_Label_theme_constant_shadow_as_outline:
  284. .. rst-class:: classref-themeproperty
  285. :ref:`int<class_int>` **shadow_as_outline** = ``0``
  286. Boolean value. If set to 1 (``true``), the shadow will be displayed around the whole text as an outline.
  287. .. rst-class:: classref-item-separator
  288. ----
  289. .. _class_Label_theme_constant_shadow_offset_x:
  290. .. rst-class:: classref-themeproperty
  291. :ref:`int<class_int>` **shadow_offset_x** = ``1``
  292. The horizontal offset of the text's shadow.
  293. .. rst-class:: classref-item-separator
  294. ----
  295. .. _class_Label_theme_constant_shadow_offset_y:
  296. .. rst-class:: classref-themeproperty
  297. :ref:`int<class_int>` **shadow_offset_y** = ``1``
  298. The vertical offset of the text's shadow.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_Label_theme_font_font:
  302. .. rst-class:: classref-themeproperty
  303. :ref:`Font<class_Font>` **font**
  304. :ref:`Font<class_Font>` used for the **Label**'s text.
  305. .. rst-class:: classref-item-separator
  306. ----
  307. .. _class_Label_theme_style_normal:
  308. .. rst-class:: classref-themeproperty
  309. :ref:`StyleBox<class_StyleBox>` **normal**
  310. Background :ref:`StyleBox<class_StyleBox>` for the **Label**.
  311. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  312. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  313. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  314. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`