A control for displaying text that can contain different font styles, images, and basic formatting.
A control for displaying text that can contain custom fonts, images, and basic formatting. [RichTextLabel] manages these as an internal tag stack. It also adapts itself to given width/heights.
[b]Note:[/b] Assignments to [member text] clear the tag stack and reconstruct it from the property's contents. Any edits made to [member text] will erase previous edits made from other manual sources such as [method append_text] and the [code]push_*[/code] / [method pop] methods.
[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].
[b]Note:[/b] [code]push_*/pop_*[/code] functions won't affect BBCode.
[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] property.
$DOCS_URL/tutorials/ui/bbcode_in_richtextlabel.html
https://godotengine.org/asset-library/asset/132
https://godotengine.org/asset-library/asset/677
Adds an image's opening and closing tags to the tag stack, optionally providing a [param width] and [param height] to resize the image, a [param color] to tint the image and a [param region] to only use parts of the image.
If [param width] or [param height] is set to 0, the image size will be adjusted in order to keep the original aspect ratio.
If [param width] and [param height] are not set, but [param region] is, the region's rect will be used.
Adds raw non-BBCode-parsed text to the tag stack.
Parses [param bbcode] and adds tags to the tag stack as needed.
[b]Note:[/b] Using this method, you can't close a tag that was opened in a previous [method append_text] 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 text] instead of using [method append_text].
Clears the tag stack.
[b]Note:[/b] This method will not modify [member text], but setting [member text] to an empty string also clears the stack.
Clears the current selection.
Returns the line number of the character position provided.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the paragraph number of the character position provided.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the height of the content.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the width of the content.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the total number of lines in the text. Wrapped text is counted as multiple lines.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the vertical offset of the line found at the provided index.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the [PopupMenu] of this [RichTextLabel]. By default, this menu is displayed when right-clicking on the [RichTextLabel].
You can add custom menu items or remove standard ones. Make sure your IDs don't conflict with the standard ones (see [enum MenuItems]). For example:
[codeblocks]
[gdscript]
func _ready():
var menu = get_menu()
# Remove "Select All" item.
menu.remove_item(MENU_SELECT_ALL)
# Add custom items.
menu.add_separator()
menu.add_item("Duplicate Text", MENU_MAX + 1)
# Connect callback.
menu.id_pressed.connect(_on_item_pressed)
func _on_item_pressed(id):
if id == MENU_MAX + 1:
add_text("\n" + get_parsed_text())
[/gdscript]
[csharp]
public override void _Ready()
{
var menu = GetMenu();
// Remove "Select All" item.
menu.RemoveItem(RichTextLabel.MenuItems.SelectAll);
// Add custom items.
menu.AddSeparator();
menu.AddItem("Duplicate Text", RichTextLabel.MenuItems.Max + 1);
// Add event handler.
menu.IdPressed += OnItemPressed;
}
public void OnItemPressed(int id)
{
if (id == TextEdit.MenuItems.Max + 1)
{
AddText("\n" + GetParsedText());
}
}
[/csharp]
[/codeblocks]
[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 Window.visible] property.
Returns the total number of paragraphs (newlines or [code]p[/code] tags in the tag stack's text tags). Considers wrapped text as one paragraph.
Returns the vertical offset of the paragraph found at the provided index.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the text without BBCode mark-up.
Returns the current selection text. Does not include BBCodes.
Returns the current selection first character index if a selection is active, [code]-1[/code] otherwise. Does not include BBCodes.
Returns the current selection last character index if a selection is active, [code]-1[/code] otherwise. Does not include BBCodes.
Returns the total number of characters from text tags. Does not include BBCodes.
Returns the vertical scrollbar.
[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.
Returns the number of visible lines.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Returns the number of visible paragraphs. A paragraph is considered visible if at least one of its lines is visible.
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_ready] or [signal finished] to determine whether document is fully loaded.
Installs a custom effect. [param effect] should be a valid [RichTextEffect].
Returns whether the menu is visible. Use this instead of [code]get_menu().visible[/code] to improve performance (so the creation of the menu is avoided).
If [member threaded] is enabled, returns [code]true[/code] if the background thread has finished text processing, otherwise always return [code]true[/code].
Executes a given action as defined in the [enum MenuItems] enum.
Adds a newline tag to the tag stack.
The assignment version of [method append_text]. Clears the tag stack and inserts the new content.
Parses BBCode parameter [param expressions] into a dictionary.
Terminates the current tag. Use after [code]push_*[/code] methods to close BBCodes manually. Does not need to follow [code]add_*[/code] methods.
Terminates all tags opened by [code]push_*[/code] methods.
Terminates tags opened after the last [method push_context] call (including context marker), or all tags if there's no context marker on the stack.
Adds a [code][bgcolor][/code] tag to the tag stack.
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.
Adds a [code][font][/code] tag with a bold italics font to the tag stack.
Adds a [code][cell][/code] tag to the tag stack. Must be inside a [code][table][/code] tag. See [method push_table] for details.
Adds a [code][color][/code] tag to the tag stack.
Adds a context marker to the tag stack. See [method pop_context].
Adds a custom effect tag to the tag stack. The effect does not need to be in [member custom_effects]. The environment is directly passed to the effect.
Adds a [code][dropcap][/code] tag to the tag stack. Drop cap (dropped capital) is a decorative element at the beginning of a paragraph that is larger than the rest of the text.
Adds a [code][fgcolor][/code] tag to the tag stack.
Adds a [code][font][/code] tag to the tag stack. Overrides default fonts for its duration.
Adds a [code][font_size][/code] tag to the tag stack. Overrides default font size for its duration.
Adds a [code][hint][/code] tag to the tag stack. Same as BBCode [code][hint=something]{text}[/hint][/code].
Adds an [code][indent][/code] tag to the tag stack. Multiplies [param level] by current [member tab_size] to determine new margin length.
Adds a [code][font][/code] tag with an italics font to the tag stack. This is the same as adding an [code][i][/code] tag if not currently in a [code][b][/code] tag.
Adds [code][ol][/code] or [code][ul][/code] tag to the tag stack. Multiplies [param level] by current [member tab_size] to determine new margin length.
Adds a meta tag to the tag stack. Similar to the BBCode [code][url=something]{text}[/url][/code], but supports non-[String] metadata types.
Adds a [code][font][/code] tag with a monospace font to the tag stack.
Adds a [code][font][/code] tag with a normal font to the tag stack.
Adds a [code][outline_color][/code] tag to the tag stack. Adds text outline for its duration.
Adds a [code][outline_size][/code] tag to the tag stack. Overrides default text outline size for its duration.
Adds a [code][p][/code] tag to the tag stack.
Adds a [code][s][/code] tag to the tag stack.
Adds a [code][table=columns,inline_align][/code] tag to the tag stack.
Adds a [code][u][/code] tag to the tag stack.
Removes a paragraph of content from the label. Returns [code]true[/code] if the paragraph exists.
The [param paragraph] argument is the index of the paragraph to remove, it can take values in the interval [code][0, get_paragraph_count() - 1][/code].
Scrolls the window's top line to match [param line].
Scrolls the window's top line to match first line of the [param paragraph].
Scrolls to the beginning of the current selection.
Select all the text.
If [member selection_enabled] is [code]false[/code], no selection will occur.
Sets color of a table cell border.
Sets inner padding of a table cell.
Sets color of a table cell. Separate colors for alternating rows can be specified.
Sets minimum and maximum size overrides for a table cell.
Edits the selected column's expansion options. If [param expand] is [code]true[/code], the column expands in proportion to its expansion ratio versus the other columns' ratios.
For example, 2 columns with ratios 3 and 4 plus 70 pixels in available width would expand 30 and 40 pixels, respectively.
If [param expand] is [code]false[/code], the column will not contribute to the total ratio.
If set to something other than [constant TextServer.AUTOWRAP_OFF], the text gets wrapped inside the node's bounding rectangle. To see how each mode behaves, see [enum TextServer.AutowrapMode].
If [code]true[/code], the label uses BBCode formatting.
If [code]true[/code], a right-click displays the context menu.
The currently installed custom effects. This is an array of [RichTextEffect]s.
To add a custom effect, it's more convenient to use [method install_effect].
If [code]true[/code], the selected text will be deselected when focus is lost.
If [code]true[/code], the label's minimum size will be automatically updated to fit its content, matching the behavior of [Label].
If [code]true[/code], the label underlines hint tags such as [code][hint=description]{text}[/hint][/code].
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
If [code]true[/code], the label underlines meta tags such as [code][url]{text}[/url][/code].
The delay after which the loading progress bar is displayed, in milliseconds. Set to [code]-1[/code] to disable progress bar entirely.
[b]Note:[/b] Progress bar is displayed only if [member threaded] is enabled.
If [code]true[/code], the scrollbar is visible. Setting this to [code]false[/code] does not block scrolling completely. See [method scroll_to_line].
If [code]true[/code], the window scrolls down to display new content automatically.
If [code]true[/code], the label allows text selection.
If [code]true[/code], shortcut keys for context menu items are enabled, even if the context menu is disabled.
Set BiDi algorithm override for the structured text.
Set additional options for BiDi override.
The number of spaces associated with a single tab length. Does not affect [code]\t[/code] in text tags, only indent tags.
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.
[b]Note:[/b] If [member bbcode_enabled] is [code]true[/code], it is unadvised to use the [code]+=[/code] operator with [code]text[/code] (e.g. [code]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_text] for adding text instead, unless you absolutely need to close a tag that was opened in an earlier method call.
Base text writing direction.
If [code]true[/code], text processing is done in a background thread.
The number of characters to display. If set to [code]-1[/code], all characters are displayed. This can be useful when animating the text appearing in a dialog box.
[b]Note:[/b] Setting this property updates [member visible_ratio] accordingly.
Sets the clipping behavior when [member visible_characters] or [member visible_ratio] is set. See [enum TextServer.VisibleCharactersBehavior] for more info.
The fraction of characters to display, relative to the total number of characters (see [method get_total_character_count]). If set to [code]1.0[/code], all characters are displayed. If set to [code]0.5[/code], only half of the characters will be displayed. This can be useful when animating the text appearing in a dialog box.
[b]Note:[/b] Setting this property updates [member visible_characters] accordingly.
Triggered when the document is fully loaded.
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.
Triggers when the mouse exits a meta tag.
Triggers when the mouse enters a meta tag.
Each list item has a number marker.
Each list item has a letter marker.
Each list item has a roman number marker.
Each list item has a filled circle marker.
Copies the selected text.
Selects the whole [RichTextLabel] text.
Represents the size of the [enum MenuItems] enum.
The default text color.
The default tint of text outline.
The color of selected text, used when [member selection_enabled] is [code]true[/code]. If equal to [code]Color(0, 0, 0, 0)[/code], it will be ignored.
The color of the font's shadow.
The color of the selection box.
The default cell border color.
The default background color for even rows.
The default background color for odd rows.
The vertical space between lines.
The size of the text outline.
[b]Note:[/b] If using a font with [member FontFile.multichannel_signed_distance_field] enabled, its [member FontFile.msdf_pixel_range] must be set to at least [i]twice[/i] the value of [theme_item outline_size] for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
The horizontal offset of the font's shadow.
The vertical offset of the font's shadow.
The size of the shadow outline.
The horizontal separation of elements in a table.
The vertical separation of elements in a table.
The horizontal padding around a highlighting and background color box.
The vertical padding around a highlighting and background color box.
The font used for bold text.
The font used for bold italics text.
The font used for italics text.
The font used for monospace text.
The default text font.
The font size used for bold text.
The font size used for bold italics text.
The font size used for italics text.
The font size used for monospace text.
The default text font size.
The background used when the [RichTextLabel] is focused. The [code]focus[/code] [StyleBox] is displayed [i]over[/i] the base [StyleBox], so a partially transparent [StyleBox] should be used to ensure the base [StyleBox] remains visible. A [StyleBox] that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a [StyleBoxEmpty] resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
The normal background for the [RichTextLabel].