class_label.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Label.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Label:
  5. Label
  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. Displays plain text in a line or wrapped inside a rectangle. For formatted text, use :ref:`RichTextLabel<class_richtextlabel>`.
  12. Member Functions
  13. ----------------
  14. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`int<class_int>` | :ref:`get_align<class_Label_get_align>` **(** **)** const |
  16. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`int<class_int>` | :ref:`get_line_count<class_Label_get_line_count>` **(** **)** const |
  18. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`int<class_int>` | :ref:`get_line_height<class_Label_get_line_height>` **(** **)** const |
  20. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`get_lines_skipped<class_Label_get_lines_skipped>` **(** **)** const |
  22. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`int<class_int>` | :ref:`get_max_lines_visible<class_Label_get_max_lines_visible>` **(** **)** const |
  24. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`float<class_float>` | :ref:`get_percent_visible<class_Label_get_percent_visible>` **(** **)** const |
  26. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`String<class_string>` | :ref:`get_text<class_Label_get_text>` **(** **)** const |
  28. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`get_total_character_count<class_Label_get_total_character_count>` **(** **)** const |
  30. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_valign<class_Label_get_valign>` **(** **)** const |
  32. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_visible_characters<class_Label_get_visible_characters>` **(** **)** const |
  34. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_visible_line_count<class_Label_get_visible_line_count>` **(** **)** const |
  36. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`has_autowrap<class_Label_has_autowrap>` **(** **)** const |
  38. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`is_clipping_text<class_Label_is_clipping_text>` **(** **)** const |
  40. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`is_uppercase<class_Label_is_uppercase>` **(** **)** const |
  42. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`set_align<class_Label_set_align>` **(** :ref:`int<class_int>` align **)** |
  44. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`set_autowrap<class_Label_set_autowrap>` **(** :ref:`bool<class_bool>` enable **)** |
  46. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`set_clip_text<class_Label_set_clip_text>` **(** :ref:`bool<class_bool>` enable **)** |
  48. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`set_lines_skipped<class_Label_set_lines_skipped>` **(** :ref:`int<class_int>` lines_skipped **)** |
  50. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`set_max_lines_visible<class_Label_set_max_lines_visible>` **(** :ref:`int<class_int>` lines_visible **)** |
  52. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_percent_visible<class_Label_set_percent_visible>` **(** :ref:`float<class_float>` percent_visible **)** |
  54. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_text<class_Label_set_text>` **(** :ref:`String<class_string>` text **)** |
  56. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_uppercase<class_Label_set_uppercase>` **(** :ref:`bool<class_bool>` enable **)** |
  58. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_valign<class_Label_set_valign>` **(** :ref:`int<class_int>` valign **)** |
  60. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_visible_characters<class_Label_set_visible_characters>` **(** :ref:`int<class_int>` amount **)** |
  62. +------------------------------+---------------------------------------------------------------------------------------------------------------------+
  63. Member Variables
  64. ----------------
  65. - :ref:`int<class_int>` **align** - Controls the text's horizontal align. Supports left, center, right, and fill, or justify. Set it to one of the [code]ALIGN_*[/code] constants.
  66. - :ref:`bool<class_bool>` **autowrap** - If [code]true[/code], 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. Default: false.
  67. - :ref:`bool<class_bool>` **clip_text** - If [code]true[/code], the Label only shows the text that fits inside its bounding rectangle. It also lets you scale the node down freely.
  68. - :ref:`int<class_int>` **lines_skipped** - The node ignores the first [code]lines_skipped[/code] lines before it starts to display text.
  69. - :ref:`int<class_int>` **max_lines_visible** - Limits the lines of text the node shows on screen.
  70. - :ref:`float<class_float>` **percent_visible** - Limits the count of visible characters. If you set [code]percent_visible[/code] to 50, only up to half of the text's characters will display on screen. Useful to animate the text in a dialog box.
  71. - :ref:`String<class_string>` **text** - The text to display on screen.
  72. - :ref:`bool<class_bool>` **uppercase** - If [code]true[/code], all the text displays as UPPERCASE.
  73. - :ref:`int<class_int>` **valign** - Controls the text's vertical align. Supports top, center, bottom, and fill. Set it to one of the [code]VALIGN_*[/code] constants.
  74. Numeric Constants
  75. -----------------
  76. - **ALIGN_LEFT** = **0** --- Align rows to the left (default).
  77. - **ALIGN_CENTER** = **1** --- Align rows centered.
  78. - **ALIGN_RIGHT** = **2** --- Align rows to the right (default).
  79. - **ALIGN_FILL** = **3** --- Expand row whitespaces to fit the width.
  80. - **VALIGN_TOP** = **0** --- Align the whole text to the top.
  81. - **VALIGN_CENTER** = **1** --- Align the whole text to the center.
  82. - **VALIGN_BOTTOM** = **2** --- Align the whole text to the bottom.
  83. - **VALIGN_FILL** = **3** --- Align the whole text by spreading the rows.
  84. Description
  85. -----------
  86. 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.
  87. Member Function Description
  88. ---------------------------
  89. .. _class_Label_get_align:
  90. - :ref:`int<class_int>` **get_align** **(** **)** const
  91. Returns the alignment mode (any of the ALIGN\_\* enumeration values).
  92. .. _class_Label_get_line_count:
  93. - :ref:`int<class_int>` **get_line_count** **(** **)** const
  94. Returns the amount of lines of text the Label has.
  95. .. _class_Label_get_line_height:
  96. - :ref:`int<class_int>` **get_line_height** **(** **)** const
  97. Returns the font size in pixels.
  98. .. _class_Label_get_lines_skipped:
  99. - :ref:`int<class_int>` **get_lines_skipped** **(** **)** const
  100. Returns the the number of lines to skip before displaying.
  101. .. _class_Label_get_max_lines_visible:
  102. - :ref:`int<class_int>` **get_max_lines_visible** **(** **)** const
  103. Returns the maximum number of lines to display. Returns -1 if unrestricted.
  104. .. _class_Label_get_percent_visible:
  105. - :ref:`float<class_float>` **get_percent_visible** **(** **)** const
  106. Returns the maximum number of characters to display as a percentage of the total text.
  107. .. _class_Label_get_text:
  108. - :ref:`String<class_string>` **get_text** **(** **)** const
  109. Returns the label text. Text can contain newlines.
  110. .. _class_Label_get_total_character_count:
  111. - :ref:`int<class_int>` **get_total_character_count** **(** **)** const
  112. Returns the total length of the text.
  113. .. _class_Label_get_valign:
  114. - :ref:`int<class_int>` **get_valign** **(** **)** const
  115. Returns the vertical alignment mode (any of the VALIGN\_\* enumeration values).
  116. .. _class_Label_get_visible_characters:
  117. - :ref:`int<class_int>` **get_visible_characters** **(** **)** const
  118. Returns the restricted number of characters to display. Returns -1 if unrestricted.
  119. .. _class_Label_get_visible_line_count:
  120. - :ref:`int<class_int>` **get_visible_line_count** **(** **)** const
  121. Returns the number of lines shown. Useful if the ``Label`` 's height cannot currently display all lines.
  122. .. _class_Label_has_autowrap:
  123. - :ref:`bool<class_bool>` **has_autowrap** **(** **)** const
  124. Returns ``true`` if *autowrap* mode (see :ref:`set_autowrap<class_Label_set_autowrap>`).
  125. .. _class_Label_is_clipping_text:
  126. - :ref:`bool<class_bool>` **is_clipping_text** **(** **)** const
  127. Returns ``true`` if text would be cut off if it is too wide.
  128. .. _class_Label_is_uppercase:
  129. - :ref:`bool<class_bool>` **is_uppercase** **(** **)** const
  130. Returns ``true`` if text is displayed in all capitals.
  131. .. _class_Label_set_align:
  132. - void **set_align** **(** :ref:`int<class_int>` align **)**
  133. Sets the alignment mode to any of the ALIGN\_\* enumeration values.
  134. .. _class_Label_set_autowrap:
  135. - void **set_autowrap** **(** :ref:`bool<class_bool>` enable **)**
  136. Set *autowrap* mode. When enabled, autowrap will fit text to the control width, breaking sentences when they exceed the available horizontal space. When disabled, the label minimum width becomes the width of the longest row, and the minimum height large enough to fit all rows.
  137. .. _class_Label_set_clip_text:
  138. - void **set_clip_text** **(** :ref:`bool<class_bool>` enable **)**
  139. Cuts off the rest of the text if it is too wide.
  140. .. _class_Label_set_lines_skipped:
  141. - void **set_lines_skipped** **(** :ref:`int<class_int>` lines_skipped **)**
  142. Sets the number of lines to skip before displaying. Useful for scrolling text.
  143. .. _class_Label_set_max_lines_visible:
  144. - void **set_max_lines_visible** **(** :ref:`int<class_int>` lines_visible **)**
  145. Restricts the number of lines to display. Set to -1 to disable.
  146. .. _class_Label_set_percent_visible:
  147. - void **set_percent_visible** **(** :ref:`float<class_float>` percent_visible **)**
  148. Restricts the number of characters to display (as a percentage of the total text).
  149. .. _class_Label_set_text:
  150. - void **set_text** **(** :ref:`String<class_string>` text **)**
  151. Set the label text. Text can contain newlines.
  152. .. _class_Label_set_uppercase:
  153. - void **set_uppercase** **(** :ref:`bool<class_bool>` enable **)**
  154. Display text in all capitals.
  155. .. _class_Label_set_valign:
  156. - void **set_valign** **(** :ref:`int<class_int>` valign **)**
  157. Sets the vertical alignment mode to any of the VALIGN\_\* enumeration values.
  158. .. _class_Label_set_visible_characters:
  159. - void **set_visible_characters** **(** :ref:`int<class_int>` amount **)**
  160. Restricts the number of characters to display. Set to -1 to disable.