class_richtextlabel.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the RichTextLabel.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_RichTextLabel:
  5. RichTextLabel
  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. Label that displays rich text.
  12. Member Functions
  13. ----------------
  14. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | void | :ref:`add_image<class_RichTextLabel_add_image>` **(** :ref:`Texture<class_texture>` image **)** |
  16. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`add_text<class_RichTextLabel_add_text>` **(** :ref:`String<class_string>` text **)** |
  18. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`int<class_int>` | :ref:`append_bbcode<class_RichTextLabel_append_bbcode>` **(** :ref:`String<class_string>` bbcode **)** |
  20. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | void | :ref:`clear<class_RichTextLabel_clear>` **(** **)** |
  22. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`int<class_int>` | :ref:`get_line_count<class_RichTextLabel_get_line_count>` **(** **)** const |
  24. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`int<class_int>` | :ref:`get_tab_size<class_RichTextLabel_get_tab_size>` **(** **)** const |
  26. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`String<class_string>` | :ref:`get_text<class_RichTextLabel_get_text>` **(** **)** |
  28. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`get_total_character_count<class_RichTextLabel_get_total_character_count>` **(** **)** const |
  30. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`VScrollBar<class_vscrollbar>` | :ref:`get_v_scroll<class_RichTextLabel_get_v_scroll>` **(** **)** |
  32. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_visible_line_count<class_RichTextLabel_get_visible_line_count>` **(** **)** const |
  34. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`is_meta_underlined<class_RichTextLabel_is_meta_underlined>` **(** **)** const |
  36. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`is_scroll_active<class_RichTextLabel_is_scroll_active>` **(** **)** const |
  38. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`is_scroll_following<class_RichTextLabel_is_scroll_following>` **(** **)** const |
  40. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`is_selection_enabled<class_RichTextLabel_is_selection_enabled>` **(** **)** const |
  42. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`newline<class_RichTextLabel_newline>` **(** **)** |
  44. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`int<class_int>` | :ref:`parse_bbcode<class_RichTextLabel_parse_bbcode>` **(** :ref:`String<class_string>` bbcode **)** |
  46. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`pop<class_RichTextLabel_pop>` **(** **)** |
  48. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`push_align<class_RichTextLabel_push_align>` **(** :ref:`int<class_int>` align **)** |
  50. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`push_cell<class_RichTextLabel_push_cell>` **(** **)** |
  52. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`push_color<class_RichTextLabel_push_color>` **(** :ref:`Color<class_color>` color **)** |
  54. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`push_font<class_RichTextLabel_push_font>` **(** :ref:`Font<class_font>` font **)** |
  56. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`push_indent<class_RichTextLabel_push_indent>` **(** :ref:`int<class_int>` level **)** |
  58. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`push_list<class_RichTextLabel_push_list>` **(** :ref:`int<class_int>` type **)** |
  60. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`push_meta<class_RichTextLabel_push_meta>` **(** :ref:`Variant<class_variant>` data **)** |
  62. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`push_table<class_RichTextLabel_push_table>` **(** :ref:`int<class_int>` columns **)** |
  64. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`push_underline<class_RichTextLabel_push_underline>` **(** **)** |
  66. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`remove_line<class_RichTextLabel_remove_line>` **(** :ref:`int<class_int>` line **)** |
  68. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`scroll_to_line<class_RichTextLabel_scroll_to_line>` **(** :ref:`int<class_int>` line **)** |
  70. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`set_meta_underline<class_RichTextLabel_set_meta_underline>` **(** :ref:`bool<class_bool>` enable **)** |
  72. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`set_scroll_active<class_RichTextLabel_set_scroll_active>` **(** :ref:`bool<class_bool>` active **)** |
  74. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`set_scroll_follow<class_RichTextLabel_set_scroll_follow>` **(** :ref:`bool<class_bool>` follow **)** |
  76. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`set_selection_enabled<class_RichTextLabel_set_selection_enabled>` **(** :ref:`bool<class_bool>` enabled **)** |
  78. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`set_tab_size<class_RichTextLabel_set_tab_size>` **(** :ref:`int<class_int>` spaces **)** |
  80. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`set_table_column_expand<class_RichTextLabel_set_table_column_expand>` **(** :ref:`int<class_int>` column, :ref:`bool<class_bool>` expand, :ref:`int<class_int>` ratio **)** |
  82. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`set_text<class_RichTextLabel_set_text>` **(** :ref:`String<class_string>` text **)** |
  84. +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. Signals
  86. -------
  87. .. _class_RichTextLabel_meta_clicked:
  88. - **meta_clicked** **(** :ref:`Nil<class_nil>` meta **)**
  89. Triggered when the user clicks on content between url tags. If the meta is defined in text, e.g. ``[url={"data"="hi"}]hi[/url]``, then the parameter for this signal will be a :ref:`String<class_string>` type. If a particular type or an object is desired, the :ref:`push_meta<class_RichTextLabel_push_meta>` method must be used to manually insert the data into the tag stack.
  90. .. _class_RichTextLabel_meta_hover_ended:
  91. - **meta_hover_ended** **(** :ref:`Nil<class_nil>` meta **)**
  92. Triggers when the mouse exits a meta tag.
  93. .. _class_RichTextLabel_meta_hover_started:
  94. - **meta_hover_started** **(** :ref:`Nil<class_nil>` meta **)**
  95. Triggers when the mouse enters a meta tag.
  96. Member Variables
  97. ----------------
  98. .. _class_RichTextLabel_bbcode_enabled:
  99. - :ref:`bool<class_bool>` **bbcode_enabled** - If ``true`` the label uses BBCode formatting. Default value: ``false``.
  100. .. _class_RichTextLabel_bbcode_text:
  101. - :ref:`String<class_string>` **bbcode_text** - The label's text in BBCode format. Is not representative of manual modifications to the internal tag stack. Erases changes made by other methods when edited.
  102. .. _class_RichTextLabel_override_selected_font_color:
  103. - :ref:`bool<class_bool>` **override_selected_font_color** - If ``true`` the label uses the custom font color. Default value: ``false``.
  104. .. _class_RichTextLabel_percent_visible:
  105. - :ref:`float<class_float>` **percent_visible** - The text's visibility, as a :ref:`float<class_float>` between 0.0 and 1.0.
  106. .. _class_RichTextLabel_visible_characters:
  107. - :ref:`int<class_int>` **visible_characters** - The restricted number of characters to display in the label.
  108. Numeric Constants
  109. -----------------
  110. - **ALIGN_LEFT** = **0**
  111. - **ALIGN_CENTER** = **1**
  112. - **ALIGN_RIGHT** = **2**
  113. - **ALIGN_FILL** = **3**
  114. - **LIST_NUMBERS** = **0**
  115. - **LIST_LETTERS** = **1**
  116. - **LIST_DOTS** = **2**
  117. - **ITEM_FRAME** = **0**
  118. - **ITEM_TEXT** = **1**
  119. - **ITEM_IMAGE** = **2**
  120. - **ITEM_NEWLINE** = **3**
  121. - **ITEM_FONT** = **4**
  122. - **ITEM_COLOR** = **5**
  123. - **ITEM_UNDERLINE** = **6**
  124. - **ITEM_ALIGN** = **7**
  125. - **ITEM_INDENT** = **8**
  126. - **ITEM_LIST** = **9**
  127. - **ITEM_TABLE** = **10**
  128. - **ITEM_META** = **11**
  129. Description
  130. -----------
  131. Rich text can contain custom text, fonts, images and some basic formatting. The label manages these as an internal tag stack. It also adapts itself to given width/heights.
  132. Note that assignments to :ref:`bbcode_text<class_RichTextLabel_bbcode_text>` clear the tag stack and reconstruct it from the property's contents. Any edits made to :ref:`bbcode_text<class_RichTextLabel_bbcode_text>` will erase previous edits made from other manual sources such as :ref:`append_bbcode<class_RichTextLabel_append_bbcode>` and the ``push\_\*`` / :ref:`pop<class_RichTextLabel_pop>` methods.
  133. Member Function Description
  134. ---------------------------
  135. .. _class_RichTextLabel_add_image:
  136. - void **add_image** **(** :ref:`Texture<class_texture>` image **)**
  137. Adds an image's opening and closing tags to the tag stack.
  138. .. _class_RichTextLabel_add_text:
  139. - void **add_text** **(** :ref:`String<class_string>` text **)**
  140. Adds raw non-bbcode-parsed text to the tag stack.
  141. .. _class_RichTextLabel_append_bbcode:
  142. - :ref:`int<class_int>` **append_bbcode** **(** :ref:`String<class_string>` bbcode **)**
  143. Parses ``bbcode`` and adds tags to the tag stack as needed. Returns the result of the parsing, ``OK`` if successful.
  144. .. _class_RichTextLabel_clear:
  145. - void **clear** **(** **)**
  146. Clears the tag stack and sets :ref:`bbcode_text<class_RichTextLabel_bbcode_text>` to an empty string.
  147. .. _class_RichTextLabel_get_line_count:
  148. - :ref:`int<class_int>` **get_line_count** **(** **)** const
  149. Returns the total number of newlines in the tag stack's text tags. Considers wrapped text as one line.
  150. .. _class_RichTextLabel_get_tab_size:
  151. - :ref:`int<class_int>` **get_tab_size** **(** **)** const
  152. Returns the number of spaces associated with a single tab length. Does not affect "\t" in text tags, only indent tags.
  153. .. _class_RichTextLabel_get_text:
  154. - :ref:`String<class_string>` **get_text** **(** **)**
  155. Returns the raw content of :ref:`bbcode_text<class_RichTextLabel_bbcode_text>`.
  156. .. _class_RichTextLabel_get_total_character_count:
  157. - :ref:`int<class_int>` **get_total_character_count** **(** **)** const
  158. Returns the total number of characters from text tags. Does not include bbcodes.
  159. .. _class_RichTextLabel_get_v_scroll:
  160. - :ref:`VScrollBar<class_vscrollbar>` **get_v_scroll** **(** **)**
  161. Returns the vertical scrollbar.
  162. .. _class_RichTextLabel_get_visible_line_count:
  163. - :ref:`int<class_int>` **get_visible_line_count** **(** **)** const
  164. Returns the number of visible lines.
  165. .. _class_RichTextLabel_is_meta_underlined:
  166. - :ref:`bool<class_bool>` **is_meta_underlined** **(** **)** const
  167. Returns ``true`` if the label underlines meta tags such as url{text}.
  168. .. _class_RichTextLabel_is_scroll_active:
  169. - :ref:`bool<class_bool>` **is_scroll_active** **(** **)** const
  170. Returns ``true`` if the scrollbar is visible. Does not block scrolling completely. See :ref:`scroll_to_line<class_RichTextLabel_scroll_to_line>`.
  171. .. _class_RichTextLabel_is_scroll_following:
  172. - :ref:`bool<class_bool>` **is_scroll_following** **(** **)** const
  173. Returns ``true`` if the window scrolls down to display new content automatically.
  174. .. _class_RichTextLabel_is_selection_enabled:
  175. - :ref:`bool<class_bool>` **is_selection_enabled** **(** **)** const
  176. Returns ``true`` if the label allows text selection.
  177. .. _class_RichTextLabel_newline:
  178. - void **newline** **(** **)**
  179. Adds a newline tag to the tag stack.
  180. .. _class_RichTextLabel_parse_bbcode:
  181. - :ref:`int<class_int>` **parse_bbcode** **(** :ref:`String<class_string>` bbcode **)**
  182. The assignment version of :ref:`append_bbcode<class_RichTextLabel_append_bbcode>`. Clears the tag stack and inserts the new content. Returns ``OK`` if parses ``bbcode`` successfully.
  183. .. _class_RichTextLabel_pop:
  184. - void **pop** **(** **)**
  185. Terminates the current tag. Use after ``push\_\*`` methods to close bbcodes manually. Does not need to follow ``add\_\*`` methods.
  186. .. _class_RichTextLabel_push_align:
  187. - void **push_align** **(** :ref:`int<class_int>` align **)**
  188. Adds a ``[right]`` tag to the tag stack.
  189. .. _class_RichTextLabel_push_cell:
  190. - void **push_cell** **(** **)**
  191. Adds a ``[cell]`` tag to the tag stack. Must be inside a table tag. See :ref:`push_table<class_RichTextLabel_push_table>` for details.
  192. .. _class_RichTextLabel_push_color:
  193. - void **push_color** **(** :ref:`Color<class_color>` color **)**
  194. Adds a ``[color]`` tag to the tag stack.
  195. .. _class_RichTextLabel_push_font:
  196. - void **push_font** **(** :ref:`Font<class_font>` font **)**
  197. Adds a ``[font]`` tag to the tag stack. Overrides default fonts for its duration.
  198. .. _class_RichTextLabel_push_indent:
  199. - void **push_indent** **(** :ref:`int<class_int>` level **)**
  200. Adds an ``[indent]`` tag to the tag stack. Multiplies "level" by current tab_size to determine new margin length.
  201. .. _class_RichTextLabel_push_list:
  202. - void **push_list** **(** :ref:`int<class_int>` type **)**
  203. Adds a list tag to the tag stack. Similar to the bbcodes ``[ol]`` or ``[ul]``, but supports more list types. Not fully implemented!
  204. .. _class_RichTextLabel_push_meta:
  205. - void **push_meta** **(** :ref:`Variant<class_variant>` data **)**
  206. Adds a meta tag to the tag stack. Similar to the bbcode ``[url=something]{text}[/url]``, but supports non-:ref:`String<class_string>` metadata types.
  207. .. _class_RichTextLabel_push_table:
  208. - void **push_table** **(** :ref:`int<class_int>` columns **)**
  209. Adds a ``[table=columns]`` tag to the tag stack.
  210. .. _class_RichTextLabel_push_underline:
  211. - void **push_underline** **(** **)**
  212. Adds a ``[u]`` tag to the tag stack.
  213. .. _class_RichTextLabel_remove_line:
  214. - :ref:`bool<class_bool>` **remove_line** **(** :ref:`int<class_int>` line **)**
  215. Removes a line of content from the label. Returns ``true`` if the line exists.
  216. .. _class_RichTextLabel_scroll_to_line:
  217. - void **scroll_to_line** **(** :ref:`int<class_int>` line **)**
  218. Scrolls the window's top line to match ``line``.
  219. .. _class_RichTextLabel_set_meta_underline:
  220. - void **set_meta_underline** **(** :ref:`bool<class_bool>` enable **)**
  221. If ``true`` will underline meta tags such as the url bbcode. Default value: ``true``.
  222. .. _class_RichTextLabel_set_scroll_active:
  223. - void **set_scroll_active** **(** :ref:`bool<class_bool>` active **)**
  224. If ``false`` the vertical scrollbar is hidden. Default value: ``true``.
  225. .. _class_RichTextLabel_set_scroll_follow:
  226. - void **set_scroll_follow** **(** :ref:`bool<class_bool>` follow **)**
  227. If ``true`` the window scrolls to reveal new content. Default value: ``false``.
  228. .. _class_RichTextLabel_set_selection_enabled:
  229. - void **set_selection_enabled** **(** :ref:`bool<class_bool>` enabled **)**
  230. If ``true`` text can be selected.
  231. .. _class_RichTextLabel_set_tab_size:
  232. - void **set_tab_size** **(** :ref:`int<class_int>` spaces **)**
  233. Sets the current tab length in spaces. Use with :ref:`push_indent<class_RichTextLabel_push_indent>` to redefine indent length.
  234. .. _class_RichTextLabel_set_table_column_expand:
  235. - void **set_table_column_expand** **(** :ref:`int<class_int>` column, :ref:`bool<class_bool>` expand, :ref:`int<class_int>` ratio **)**
  236. Edits the selected columns expansion options. If ``expand`` is ``true``, the column expands in proportion to its expansion ratio versus the other columns' ratios.
  237. For example, 2 columns with ratios 3 and 4 plus 70 pixels in available width would expand 30 and 40 pixels, respectively.
  238. Columns with a ``false`` expand will not contribute to the total ratio.
  239. .. _class_RichTextLabel_set_text:
  240. - void **set_text** **(** :ref:`String<class_string>` text **)**
  241. Clears the tag stack and adds a raw text tag to the top of it. Does not parse bbcodes. Does not modify :ref:`bbcode_text<class_RichTextLabel_bbcode_text>`.