RichTextLabel.xml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="RichTextLabel" inherits="Control" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. Label that displays rich text.
  5. </brief_description>
  6. <description>
  7. 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.
  8. [b]Note:[/b] Assignments to [member bbcode_text] clear the tag stack and reconstruct it from the property's contents. Any edits made to [member bbcode_text] will erase previous edits made from other manual sources such as [method append_bbcode] and the [code]push_*[/code] / [method pop] methods.
  9. [b]Note:[/b] RichTextLabel doesn't support entangled BBCode tags. For example, instead of using [code][b]bold[i]bold italic[/b]italic[/i][/code], use [code][b]bold[i]bold italic[/i][/b][i]italic[/i][/code].
  10. [b]Note:[/b] [code]push_*/pop[/code] functions won't affect BBCode.
  11. [b]Note:[/b] Unlike [Label], RichTextLabel doesn't have a [i]property[/i] to horizontally align text to the center. Instead, enable [member bbcode_enabled] and surround the text in a [code][center][/code] tag as follows: [code][center]Example[/center][/code]. There is currently no built-in way to vertically align text either, but this can be emulated by relying on anchors/containers and the [member fit_content_height] property.
  12. [b]Note:[/b] Unicode characters after [code]0xffff[/code] (such as most emoji) are [i]not[/i] supported on Windows. They will display as unknown characters instead. This will be resolved in Godot 4.0.
  13. </description>
  14. <tutorials>
  15. <link title="BBCode in RichTextLabel">$DOCS_URL/tutorials/ui/bbcode_in_richtextlabel.html</link>
  16. <link title="GUI Rich Text/BBcode Demo">https://godotengine.org/asset-library/asset/132</link>
  17. <link title="OS Test Demo">https://godotengine.org/asset-library/asset/677</link>
  18. </tutorials>
  19. <methods>
  20. <method name="add_image">
  21. <return type="void" />
  22. <argument index="0" name="image" type="Texture" />
  23. <argument index="1" name="width" type="int" default="0" />
  24. <argument index="2" name="height" type="int" default="0" />
  25. <argument index="3" name="align" type="int" enum="RichTextLabel.InlineAlign" default="2" />
  26. <description>
  27. Adds an image's opening and closing tags to the tag stack, optionally providing a [code]width[/code] and [code]height[/code] to resize the image.
  28. If [code]width[/code] or [code]height[/code] is set to 0, the image size will be adjusted in order to keep the original aspect ratio.
  29. </description>
  30. </method>
  31. <method name="add_text">
  32. <return type="void" />
  33. <argument index="0" name="text" type="String" />
  34. <description>
  35. Adds raw non-BBCode-parsed text to the tag stack.
  36. </description>
  37. </method>
  38. <method name="append_bbcode">
  39. <return type="int" enum="Error" />
  40. <argument index="0" name="bbcode" type="String" />
  41. <description>
  42. Parses [code]bbcode[/code] and adds tags to the tag stack as needed.
  43. [b]Note:[/b] Using this method, you can't close a tag that was opened in a previous [method append_bbcode] call. This is done to improve performance, especially when updating large RichTextLabels since rebuilding the whole BBCode every time would be slower. If you absolutely need to close a tag in a future method call, append the [member bbcode_text] instead of using [method append_bbcode].
  44. [b]Note:[/b] This method internals' can't possibly fail, but an error code is returned for backwards compatibility, which will always be [constant OK].
  45. </description>
  46. </method>
  47. <method name="clear">
  48. <return type="void" />
  49. <description>
  50. Clears the tag stack and sets [member bbcode_text] to an empty string.
  51. </description>
  52. </method>
  53. <method name="deselect">
  54. <return type="void" />
  55. <description>
  56. Clears the current selection.
  57. </description>
  58. </method>
  59. <method name="get_content_height" qualifiers="const">
  60. <return type="int" />
  61. <description>
  62. Returns the height of the content.
  63. </description>
  64. </method>
  65. <method name="get_line_count" qualifiers="const">
  66. <return type="int" />
  67. <description>
  68. Returns the total number of newlines in the tag stack's text tags. Considers wrapped text as one line.
  69. </description>
  70. </method>
  71. <method name="get_selected_text">
  72. <return type="String" />
  73. <description>
  74. Returns the current selection text. Does not include BBCodes.
  75. </description>
  76. </method>
  77. <method name="get_total_character_count" qualifiers="const">
  78. <return type="int" />
  79. <description>
  80. Returns the total number of characters from text tags. Does not include BBCodes.
  81. </description>
  82. </method>
  83. <method name="get_v_scroll">
  84. <return type="VScrollBar" />
  85. <description>
  86. Returns the vertical scrollbar.
  87. [b]Warning:[/b] This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their [member CanvasItem.visible] property.
  88. </description>
  89. </method>
  90. <method name="get_visible_line_count" qualifiers="const">
  91. <return type="int" />
  92. <description>
  93. Returns the number of visible lines.
  94. </description>
  95. </method>
  96. <method name="install_effect">
  97. <return type="void" />
  98. <argument index="0" name="effect" type="Variant" />
  99. <description>
  100. Installs a custom effect. [code]effect[/code] should be a valid [RichTextEffect].
  101. </description>
  102. </method>
  103. <method name="newline">
  104. <return type="void" />
  105. <description>
  106. Adds a newline tag to the tag stack.
  107. </description>
  108. </method>
  109. <method name="parse_bbcode">
  110. <return type="int" enum="Error" />
  111. <argument index="0" name="bbcode" type="String" />
  112. <description>
  113. The assignment version of [method append_bbcode]. Clears the tag stack and inserts the new content.
  114. [b]Note:[/b] This method internals' can't possibly fail, but an error code is returned for backwards compatibility, which will always be [constant OK].
  115. </description>
  116. </method>
  117. <method name="parse_expressions_for_values">
  118. <return type="Dictionary" />
  119. <argument index="0" name="expressions" type="PoolStringArray" />
  120. <description>
  121. Parses BBCode parameter [code]expressions[/code] into a dictionary.
  122. </description>
  123. </method>
  124. <method name="pop">
  125. <return type="void" />
  126. <description>
  127. Terminates the current tag. Use after [code]push_*[/code] methods to close BBCodes manually. Does not need to follow [code]add_*[/code] methods.
  128. </description>
  129. </method>
  130. <method name="push_align">
  131. <return type="void" />
  132. <argument index="0" name="align" type="int" enum="RichTextLabel.Align" />
  133. <description>
  134. Adds an [code][align][/code] tag based on the given [code]align[/code] value. See [enum Align] for possible values.
  135. </description>
  136. </method>
  137. <method name="push_bold">
  138. <return type="void" />
  139. <description>
  140. Adds a [code][font][/code] tag with a bold font to the tag stack. This is the same as adding a [code][b][/code] tag if not currently in a [code][i][/code] tag.
  141. </description>
  142. </method>
  143. <method name="push_bold_italics">
  144. <return type="void" />
  145. <description>
  146. Adds a [code][font][/code] tag with a bold italics font to the tag stack.
  147. </description>
  148. </method>
  149. <method name="push_cell">
  150. <return type="void" />
  151. <description>
  152. Adds a [code][cell][/code] tag to the tag stack. Must be inside a [code][table][/code] tag. See [method push_table] for details.
  153. </description>
  154. </method>
  155. <method name="push_color">
  156. <return type="void" />
  157. <argument index="0" name="color" type="Color" />
  158. <description>
  159. Adds a [code][color][/code] tag to the tag stack.
  160. </description>
  161. </method>
  162. <method name="push_font">
  163. <return type="void" />
  164. <argument index="0" name="font" type="Font" />
  165. <description>
  166. Adds a [code][font][/code] tag to the tag stack. Overrides default fonts for its duration.
  167. </description>
  168. </method>
  169. <method name="push_indent">
  170. <return type="void" />
  171. <argument index="0" name="level" type="int" />
  172. <description>
  173. Adds an [code][indent][/code] tag to the tag stack. Multiplies [code]level[/code] by current [member tab_size] to determine new margin length.
  174. </description>
  175. </method>
  176. <method name="push_italics">
  177. <return type="void" />
  178. <description>
  179. Adds a [code][font][/code] tag with a italics font to the tag stack. This is the same as adding a [code][i][/code] tag if not currently in a [code][b][/code] tag.
  180. </description>
  181. </method>
  182. <method name="push_list">
  183. <return type="void" />
  184. <argument index="0" name="type" type="int" enum="RichTextLabel.ListType" />
  185. <description>
  186. Adds a [code][list][/code] tag to the tag stack. Similar to the BBCodes [code][ol][/code] or [code][ul][/code], but supports more list types. Not fully implemented!
  187. </description>
  188. </method>
  189. <method name="push_meta">
  190. <return type="void" />
  191. <argument index="0" name="data" type="Variant" />
  192. <description>
  193. Adds a [code][meta][/code] tag to the tag stack. Similar to the BBCode [code][url=something]{text}[/url][/code], but supports non-[String] metadata types.
  194. </description>
  195. </method>
  196. <method name="push_mono">
  197. <return type="void" />
  198. <description>
  199. Adds a [code][font][/code] tag with a monospace font to the tag stack.
  200. </description>
  201. </method>
  202. <method name="push_normal">
  203. <return type="void" />
  204. <description>
  205. Adds a [code][font][/code] tag with a normal font to the tag stack.
  206. </description>
  207. </method>
  208. <method name="push_strikethrough">
  209. <return type="void" />
  210. <description>
  211. Adds a [code][s][/code] tag to the tag stack.
  212. </description>
  213. </method>
  214. <method name="push_table">
  215. <return type="void" />
  216. <argument index="0" name="columns" type="int" />
  217. <description>
  218. Adds a [code][table=columns][/code] tag to the tag stack.
  219. </description>
  220. </method>
  221. <method name="push_underline">
  222. <return type="void" />
  223. <description>
  224. Adds a [code][u][/code] tag to the tag stack.
  225. </description>
  226. </method>
  227. <method name="remove_line">
  228. <return type="bool" />
  229. <argument index="0" name="line" type="int" />
  230. <description>
  231. Removes a line of content from the label. Returns [code]true[/code] if the line exists.
  232. The [code]line[/code] argument is the index of the line to remove, it can take values in the interval [code][0, get_line_count() - 1][/code].
  233. </description>
  234. </method>
  235. <method name="scroll_to_line">
  236. <return type="void" />
  237. <argument index="0" name="line" type="int" />
  238. <description>
  239. Scrolls the window's top line to match [code]line[/code].
  240. </description>
  241. </method>
  242. <method name="set_table_column_expand">
  243. <return type="void" />
  244. <argument index="0" name="column" type="int" />
  245. <argument index="1" name="expand" type="bool" />
  246. <argument index="2" name="ratio" type="int" />
  247. <description>
  248. Edits the selected column's expansion options. If [code]expand[/code] is [code]true[/code], the column expands in proportion to its expansion ratio versus the other columns' ratios.
  249. For example, 2 columns with ratios 3 and 4 plus 70 pixels in available width would expand 30 and 40 pixels, respectively.
  250. If [code]expand[/code] is [code]false[/code], the column will not contribute to the total ratio.
  251. </description>
  252. </method>
  253. </methods>
  254. <members>
  255. <member name="bbcode_enabled" type="bool" setter="set_use_bbcode" getter="is_using_bbcode" default="false">
  256. If [code]true[/code], the label uses BBCode formatting.
  257. [b]Note:[/b] Trying to alter the [RichTextLabel]'s text with [method add_text] will reset this to [code]false[/code]. Use instead [method append_bbcode] to preserve BBCode formatting.
  258. </member>
  259. <member name="bbcode_text" type="String" setter="set_bbcode" getter="get_bbcode" default="&quot;&quot;">
  260. 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.
  261. [b]Note:[/b] It is unadvised to use the [code]+=[/code] operator with [code]bbcode_text[/code] (e.g. [code]bbcode_text += "some string"[/code]) as it replaces the whole text and can cause slowdowns. It will also erase all BBCode that was added to stack using [code]push_*[/code] methods. Use [method append_bbcode] for adding text instead, unless you absolutely need to close a tag that was opened in an earlier method call.
  262. </member>
  263. <member name="custom_effects" type="Array" setter="set_effects" getter="get_effects" default="[ ]">
  264. The currently installed custom effects. This is an array of [RichTextEffect]s.
  265. To add a custom effect, it's more convenient to use [method install_effect].
  266. </member>
  267. <member name="deselect_on_focus_loss_enabled" type="bool" setter="set_deselect_on_focus_loss_enabled" getter="is_deselect_on_focus_loss_enabled" default="true">
  268. If [code]true[/code], the selected text will be deselected when focus is lost.
  269. </member>
  270. <member name="fit_content_height" type="bool" setter="set_fit_content_height" getter="is_fit_content_height_enabled" default="false">
  271. If [code]true[/code], the label's height will be automatically updated to fit its content.
  272. [b]Note:[/b] This property is used as a workaround to fix issues with [RichTextLabel] in [Container]s, but it's unreliable in some cases and will be removed in future versions.
  273. </member>
  274. <member name="meta_underlined" type="bool" setter="set_meta_underline" getter="is_meta_underlined" default="true">
  275. If [code]true[/code], the label underlines meta tags such as [code][url]{text}[/url][/code].
  276. </member>
  277. <member name="override_selected_font_color" type="bool" setter="set_override_selected_font_color" getter="is_overriding_selected_font_color" default="false">
  278. If [code]true[/code], the label uses the custom font color.
  279. </member>
  280. <member name="percent_visible" type="float" setter="set_percent_visible" getter="get_percent_visible" default="1.0">
  281. The range of characters to display, as a [float] between 0.0 and 1.0. When assigned an out of range value, it's the same as assigning 1.0.
  282. [b]Note:[/b] Setting this property updates [member visible_characters] based on current [method get_total_character_count].
  283. </member>
  284. <member name="rect_clip_content" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
  285. <member name="scroll_active" type="bool" setter="set_scroll_active" getter="is_scroll_active" default="true">
  286. If [code]true[/code], the scrollbar is visible. Setting this to [code]false[/code] does not block scrolling completely. See [method scroll_to_line].
  287. </member>
  288. <member name="scroll_following" type="bool" setter="set_scroll_follow" getter="is_scroll_following" default="false">
  289. If [code]true[/code], the window scrolls down to display new content automatically.
  290. </member>
  291. <member name="selection_enabled" type="bool" setter="set_selection_enabled" getter="is_selection_enabled" default="false">
  292. If [code]true[/code], the label allows text selection.
  293. </member>
  294. <member name="tab_size" type="int" setter="set_tab_size" getter="get_tab_size" default="4">
  295. The number of spaces associated with a single tab length. Does not affect [code]\t[/code] in text tags, only indent tags.
  296. </member>
  297. <member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;">
  298. The raw text of the label.
  299. When set, clears the tag stack and adds a raw text tag to the top of it. Does not parse BBCodes. Does not modify [member bbcode_text].
  300. </member>
  301. <member name="visible_characters" type="int" setter="set_visible_characters" getter="get_visible_characters" default="-1">
  302. The restricted number of characters to display in the label. If [code]-1[/code], all characters will be displayed.
  303. [b]Note:[/b] Setting this property updates [member percent_visible] based on current [method get_total_character_count].
  304. </member>
  305. </members>
  306. <signals>
  307. <signal name="meta_clicked">
  308. <argument index="0" name="meta" type="Variant" />
  309. <description>
  310. Triggered when the user clicks on content between meta tags. If the meta is defined in text, e.g. [code][url={"data"="hi"}]hi[/url][/code], then the parameter for this signal will be a [String] type. If a particular type or an object is desired, the [method push_meta] method must be used to manually insert the data into the tag stack.
  311. </description>
  312. </signal>
  313. <signal name="meta_hover_ended">
  314. <argument index="0" name="meta" type="Variant" />
  315. <description>
  316. Triggers when the mouse exits a meta tag.
  317. </description>
  318. </signal>
  319. <signal name="meta_hover_started">
  320. <argument index="0" name="meta" type="Variant" />
  321. <description>
  322. Triggers when the mouse enters a meta tag.
  323. </description>
  324. </signal>
  325. </signals>
  326. <constants>
  327. <constant name="ALIGN_LEFT" value="0" enum="Align">
  328. Makes text left aligned.
  329. </constant>
  330. <constant name="ALIGN_CENTER" value="1" enum="Align">
  331. Makes text centered.
  332. </constant>
  333. <constant name="ALIGN_RIGHT" value="2" enum="Align">
  334. Makes text right aligned.
  335. </constant>
  336. <constant name="ALIGN_FILL" value="3" enum="Align">
  337. Makes text fill width.
  338. </constant>
  339. <constant name="INLINE_ALIGN_TOP" value="0" enum="InlineAlign">
  340. Aligns top of the inline image to the top of the text.
  341. </constant>
  342. <constant name="INLINE_ALIGN_CENTER" value="1" enum="InlineAlign">
  343. Aligns center of the inline image to the center of the text.
  344. </constant>
  345. <constant name="INLINE_ALIGN_BASELINE" value="2" enum="InlineAlign">
  346. Aligns bottom of the inline image to the baseline of the text.
  347. </constant>
  348. <constant name="INLINE_ALIGN_BOTTOM" value="3" enum="InlineAlign">
  349. Aligns bottom of the inline image to the bottom of the text.
  350. </constant>
  351. <constant name="LIST_NUMBERS" value="0" enum="ListType">
  352. Each list item has a number marker.
  353. </constant>
  354. <constant name="LIST_LETTERS" value="1" enum="ListType">
  355. Each list item has a letter marker.
  356. </constant>
  357. <constant name="LIST_DOTS" value="2" enum="ListType">
  358. Each list item has a filled circle marker.
  359. </constant>
  360. <constant name="ITEM_FRAME" value="0" enum="ItemType">
  361. </constant>
  362. <constant name="ITEM_TEXT" value="1" enum="ItemType">
  363. </constant>
  364. <constant name="ITEM_IMAGE" value="2" enum="ItemType">
  365. </constant>
  366. <constant name="ITEM_NEWLINE" value="3" enum="ItemType">
  367. </constant>
  368. <constant name="ITEM_FONT" value="4" enum="ItemType">
  369. </constant>
  370. <constant name="ITEM_COLOR" value="5" enum="ItemType">
  371. </constant>
  372. <constant name="ITEM_UNDERLINE" value="6" enum="ItemType">
  373. </constant>
  374. <constant name="ITEM_STRIKETHROUGH" value="7" enum="ItemType">
  375. </constant>
  376. <constant name="ITEM_ALIGN" value="8" enum="ItemType">
  377. </constant>
  378. <constant name="ITEM_INDENT" value="9" enum="ItemType">
  379. </constant>
  380. <constant name="ITEM_LIST" value="10" enum="ItemType">
  381. </constant>
  382. <constant name="ITEM_TABLE" value="11" enum="ItemType">
  383. </constant>
  384. <constant name="ITEM_FADE" value="12" enum="ItemType">
  385. </constant>
  386. <constant name="ITEM_SHAKE" value="13" enum="ItemType">
  387. </constant>
  388. <constant name="ITEM_WAVE" value="14" enum="ItemType">
  389. </constant>
  390. <constant name="ITEM_TORNADO" value="15" enum="ItemType">
  391. </constant>
  392. <constant name="ITEM_RAINBOW" value="16" enum="ItemType">
  393. </constant>
  394. <constant name="ITEM_CUSTOMFX" value="18" enum="ItemType">
  395. </constant>
  396. <constant name="ITEM_META" value="17" enum="ItemType">
  397. </constant>
  398. </constants>
  399. <theme_items>
  400. <theme_item name="default_color" data_type="color" type="Color" default="Color( 1, 1, 1, 1 )">
  401. The default text color.
  402. </theme_item>
  403. <theme_item name="font_color_selected" data_type="color" type="Color" default="Color( 0.49, 0.49, 0.49, 1 )">
  404. The color of selected text, used when [member selection_enabled] is [code]true[/code].
  405. </theme_item>
  406. <theme_item name="font_color_shadow" data_type="color" type="Color" default="Color( 0, 0, 0, 0 )">
  407. The color of the font's shadow.
  408. </theme_item>
  409. <theme_item name="selection_color" data_type="color" type="Color" default="Color( 0.1, 0.1, 1, 0.8 )">
  410. The color of the selection box.
  411. </theme_item>
  412. <theme_item name="line_separation" data_type="constant" type="int" default="1">
  413. The vertical space between lines.
  414. </theme_item>
  415. <theme_item name="shadow_as_outline" data_type="constant" type="int" default="0">
  416. Boolean value. If 1 ([code]true[/code]), the shadow will be displayed around the whole text as an outline.
  417. </theme_item>
  418. <theme_item name="shadow_offset_x" data_type="constant" type="int" default="1">
  419. The horizontal offset of the font's shadow.
  420. </theme_item>
  421. <theme_item name="shadow_offset_y" data_type="constant" type="int" default="1">
  422. The vertical offset of the font's shadow.
  423. </theme_item>
  424. <theme_item name="table_hseparation" data_type="constant" type="int" default="3">
  425. The horizontal separation of elements in a table.
  426. </theme_item>
  427. <theme_item name="table_vseparation" data_type="constant" type="int" default="3">
  428. The vertical separation of elements in a table.
  429. </theme_item>
  430. <theme_item name="bold_font" data_type="font" type="Font">
  431. The font used for bold text.
  432. </theme_item>
  433. <theme_item name="bold_italics_font" data_type="font" type="Font">
  434. The font used for bold italics text.
  435. </theme_item>
  436. <theme_item name="italics_font" data_type="font" type="Font">
  437. The font used for italics text.
  438. </theme_item>
  439. <theme_item name="mono_font" data_type="font" type="Font">
  440. The font used for monospace text.
  441. </theme_item>
  442. <theme_item name="normal_font" data_type="font" type="Font">
  443. The default text font.
  444. </theme_item>
  445. <theme_item name="focus" data_type="style" type="StyleBox">
  446. The background used when the [RichTextLabel] is focused.
  447. </theme_item>
  448. <theme_item name="normal" data_type="style" type="StyleBox">
  449. The normal background for the [RichTextLabel].
  450. </theme_item>
  451. </theme_items>
  452. </class>