class_label.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 Label.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Label:
  6. Label
  7. =====
  8. **Inherits:** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. Displays plain text in a line or wrapped inside a rectangle. For formatted text, use :ref:`RichTextLabel<class_RichTextLabel>`.
  10. Description
  11. -----------
  12. 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.
  13. **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.
  14. Properties
  15. ----------
  16. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  17. | :ref:`Align<enum_Label_Align>` | :ref:`align<class_Label_property_align>` | ``0`` |
  18. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  19. | :ref:`bool<class_bool>` | :ref:`autowrap<class_Label_property_autowrap>` | ``false`` |
  20. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  21. | :ref:`bool<class_bool>` | :ref:`clip_text<class_Label_property_clip_text>` | ``false`` |
  22. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  23. | :ref:`int<class_int>` | :ref:`lines_skipped<class_Label_property_lines_skipped>` | ``0`` |
  24. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  25. | :ref:`int<class_int>` | :ref:`max_lines_visible<class_Label_property_max_lines_visible>` | ``-1`` |
  26. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  27. | :ref:`MouseFilter<enum_Control_MouseFilter>` | mouse_filter | ``2`` *(parent override)* |
  28. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  29. | :ref:`float<class_float>` | :ref:`percent_visible<class_Label_property_percent_visible>` | ``1.0`` |
  30. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  31. | :ref:`int<class_int>` | size_flags_vertical | ``4`` *(parent override)* |
  32. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  33. | :ref:`String<class_String>` | :ref:`text<class_Label_property_text>` | ``""`` |
  34. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`uppercase<class_Label_property_uppercase>` | ``false`` |
  36. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  37. | :ref:`VAlign<enum_Label_VAlign>` | :ref:`valign<class_Label_property_valign>` | ``0`` |
  38. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  39. | :ref:`int<class_int>` | :ref:`visible_characters<class_Label_property_visible_characters>` | ``-1`` |
  40. +----------------------------------------------+--------------------------------------------------------------------+---------------------------+
  41. Methods
  42. -------
  43. +-----------------------+----------------------------------------------------------------------------------------------------+
  44. | :ref:`int<class_int>` | :ref:`get_line_count<class_Label_method_get_line_count>` **(** **)** |const| |
  45. +-----------------------+----------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`get_line_height<class_Label_method_get_line_height>` **(** **)** |const| |
  47. +-----------------------+----------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`get_total_character_count<class_Label_method_get_total_character_count>` **(** **)** |const| |
  49. +-----------------------+----------------------------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`get_visible_line_count<class_Label_method_get_visible_line_count>` **(** **)** |const| |
  51. +-----------------------+----------------------------------------------------------------------------------------------------+
  52. Theme Properties
  53. ----------------
  54. +---------------------------------+-----------------------+---------------------+
  55. | :ref:`Font<class_Font>` | font | |
  56. +---------------------------------+-----------------------+---------------------+
  57. | :ref:`Color<class_Color>` | font_color | Color( 1, 1, 1, 1 ) |
  58. +---------------------------------+-----------------------+---------------------+
  59. | :ref:`Color<class_Color>` | font_color_shadow | Color( 0, 0, 0, 0 ) |
  60. +---------------------------------+-----------------------+---------------------+
  61. | :ref:`Color<class_Color>` | font_outline_modulate | Color( 1, 1, 1, 1 ) |
  62. +---------------------------------+-----------------------+---------------------+
  63. | :ref:`int<class_int>` | line_spacing | 3 |
  64. +---------------------------------+-----------------------+---------------------+
  65. | :ref:`StyleBox<class_StyleBox>` | normal | |
  66. +---------------------------------+-----------------------+---------------------+
  67. | :ref:`int<class_int>` | shadow_as_outline | 0 |
  68. +---------------------------------+-----------------------+---------------------+
  69. | :ref:`int<class_int>` | shadow_offset_x | 1 |
  70. +---------------------------------+-----------------------+---------------------+
  71. | :ref:`int<class_int>` | shadow_offset_y | 1 |
  72. +---------------------------------+-----------------------+---------------------+
  73. Enumerations
  74. ------------
  75. .. _enum_Label_Align:
  76. .. _class_Label_constant_ALIGN_LEFT:
  77. .. _class_Label_constant_ALIGN_CENTER:
  78. .. _class_Label_constant_ALIGN_RIGHT:
  79. .. _class_Label_constant_ALIGN_FILL:
  80. enum **Align**:
  81. - **ALIGN_LEFT** = **0** --- Align rows to the left (default).
  82. - **ALIGN_CENTER** = **1** --- Align rows centered.
  83. - **ALIGN_RIGHT** = **2** --- Align rows to the right.
  84. - **ALIGN_FILL** = **3** --- Expand row whitespaces to fit the width.
  85. ----
  86. .. _enum_Label_VAlign:
  87. .. _class_Label_constant_VALIGN_TOP:
  88. .. _class_Label_constant_VALIGN_CENTER:
  89. .. _class_Label_constant_VALIGN_BOTTOM:
  90. .. _class_Label_constant_VALIGN_FILL:
  91. enum **VAlign**:
  92. - **VALIGN_TOP** = **0** --- Align the whole text to the top.
  93. - **VALIGN_CENTER** = **1** --- Align the whole text to the center.
  94. - **VALIGN_BOTTOM** = **2** --- Align the whole text to the bottom.
  95. - **VALIGN_FILL** = **3** --- Align the whole text by spreading the rows.
  96. Property Descriptions
  97. ---------------------
  98. .. _class_Label_property_align:
  99. - :ref:`Align<enum_Label_Align>` **align**
  100. +-----------+------------------+
  101. | *Default* | ``0`` |
  102. +-----------+------------------+
  103. | *Setter* | set_align(value) |
  104. +-----------+------------------+
  105. | *Getter* | get_align() |
  106. +-----------+------------------+
  107. 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.
  108. ----
  109. .. _class_Label_property_autowrap:
  110. - :ref:`bool<class_bool>` **autowrap**
  111. +-----------+---------------------+
  112. | *Default* | ``false`` |
  113. +-----------+---------------------+
  114. | *Setter* | set_autowrap(value) |
  115. +-----------+---------------------+
  116. | *Getter* | has_autowrap() |
  117. +-----------+---------------------+
  118. 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.
  119. ----
  120. .. _class_Label_property_clip_text:
  121. - :ref:`bool<class_bool>` **clip_text**
  122. +-----------+----------------------+
  123. | *Default* | ``false`` |
  124. +-----------+----------------------+
  125. | *Setter* | set_clip_text(value) |
  126. +-----------+----------------------+
  127. | *Getter* | is_clipping_text() |
  128. +-----------+----------------------+
  129. If ``true``, the Label only shows the text that fits inside its bounding rectangle. It also lets you scale the node down freely.
  130. ----
  131. .. _class_Label_property_lines_skipped:
  132. - :ref:`int<class_int>` **lines_skipped**
  133. +-----------+--------------------------+
  134. | *Default* | ``0`` |
  135. +-----------+--------------------------+
  136. | *Setter* | set_lines_skipped(value) |
  137. +-----------+--------------------------+
  138. | *Getter* | get_lines_skipped() |
  139. +-----------+--------------------------+
  140. The node ignores the first ``lines_skipped`` lines before it starts to display text.
  141. ----
  142. .. _class_Label_property_max_lines_visible:
  143. - :ref:`int<class_int>` **max_lines_visible**
  144. +-----------+------------------------------+
  145. | *Default* | ``-1`` |
  146. +-----------+------------------------------+
  147. | *Setter* | set_max_lines_visible(value) |
  148. +-----------+------------------------------+
  149. | *Getter* | get_max_lines_visible() |
  150. +-----------+------------------------------+
  151. Limits the lines of text the node shows on screen.
  152. ----
  153. .. _class_Label_property_percent_visible:
  154. - :ref:`float<class_float>` **percent_visible**
  155. +-----------+----------------------------+
  156. | *Default* | ``1.0`` |
  157. +-----------+----------------------------+
  158. | *Setter* | set_percent_visible(value) |
  159. +-----------+----------------------------+
  160. | *Getter* | get_percent_visible() |
  161. +-----------+----------------------------+
  162. 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.
  163. ----
  164. .. _class_Label_property_text:
  165. - :ref:`String<class_String>` **text**
  166. +-----------+-----------------+
  167. | *Default* | ``""`` |
  168. +-----------+-----------------+
  169. | *Setter* | set_text(value) |
  170. +-----------+-----------------+
  171. | *Getter* | get_text() |
  172. +-----------+-----------------+
  173. The text to display on screen.
  174. ----
  175. .. _class_Label_property_uppercase:
  176. - :ref:`bool<class_bool>` **uppercase**
  177. +-----------+----------------------+
  178. | *Default* | ``false`` |
  179. +-----------+----------------------+
  180. | *Setter* | set_uppercase(value) |
  181. +-----------+----------------------+
  182. | *Getter* | is_uppercase() |
  183. +-----------+----------------------+
  184. If ``true``, all the text displays as UPPERCASE.
  185. ----
  186. .. _class_Label_property_valign:
  187. - :ref:`VAlign<enum_Label_VAlign>` **valign**
  188. +-----------+-------------------+
  189. | *Default* | ``0`` |
  190. +-----------+-------------------+
  191. | *Setter* | set_valign(value) |
  192. +-----------+-------------------+
  193. | *Getter* | get_valign() |
  194. +-----------+-------------------+
  195. Controls the text's vertical align. Supports top, center, bottom, and fill. Set it to one of the :ref:`VAlign<enum_Label_VAlign>` constants.
  196. ----
  197. .. _class_Label_property_visible_characters:
  198. - :ref:`int<class_int>` **visible_characters**
  199. +-----------+-------------------------------+
  200. | *Default* | ``-1`` |
  201. +-----------+-------------------------------+
  202. | *Setter* | set_visible_characters(value) |
  203. +-----------+-------------------------------+
  204. | *Getter* | get_visible_characters() |
  205. +-----------+-------------------------------+
  206. Restricts the number of characters to display. Set to -1 to disable.
  207. Method Descriptions
  208. -------------------
  209. .. _class_Label_method_get_line_count:
  210. - :ref:`int<class_int>` **get_line_count** **(** **)** |const|
  211. Returns the amount of lines of text the Label has.
  212. ----
  213. .. _class_Label_method_get_line_height:
  214. - :ref:`int<class_int>` **get_line_height** **(** **)** |const|
  215. Returns the font size in pixels.
  216. ----
  217. .. _class_Label_method_get_total_character_count:
  218. - :ref:`int<class_int>` **get_total_character_count** **(** **)** |const|
  219. Returns the total number of printable characters in the text (excluding spaces and newlines).
  220. ----
  221. .. _class_Label_method_get_visible_line_count:
  222. - :ref:`int<class_int>` **get_visible_line_count** **(** **)** |const|
  223. Returns the number of lines shown. Useful if the ``Label``'s height cannot currently display all lines.
  224. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  225. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  226. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`