Up to date
This page is up to date for Godot 4.0
.
If you still find outdated information, please open an issue.
RichTextLabel¶
Inherits: Control < CanvasItem < Node < Object
Label that displays rich text.
Description¶
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.
Note: Assignments to text clear the tag stack and reconstruct it from the property's contents. Any edits made to text will erase previous edits made from other manual sources such as append_text and the push_*
/ pop methods.
Note: RichTextLabel doesn't support entangled BBCode tags. For example, instead of using [b]bold[i]bold italic[/b]italic[/i]
, use [b]bold[i]bold italic[/i][/b][i]italic[/i]
.
Note: push_*/pop
functions won't affect BBCode.
Note: Unlike Label, RichTextLabel doesn't have a property to horizontally align text to the center. Instead, enable bbcode_enabled and surround the text in a [center]
tag as follows: [center]Example[/center]
. There is currently no built-in way to vertically align text either, but this can be emulated by relying on anchors/containers and the fit_content property.
Tutorials¶
Properties¶
|
||
|
||
clip_contents |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
add_image ( Texture2D image, int width=0, int height=0, Color color=Color(1, 1, 1, 1), InlineAlignment inline_align=5, Rect2 region=Rect2(0, 0, 0, 0) ) |
void |
|
void |
append_text ( String bbcode ) |
void |
clear ( ) |
void |
deselect ( ) |
get_character_line ( int character ) |
|
get_character_paragraph ( int character ) |
|
get_content_height ( ) const |
|
get_content_width ( ) const |
|
get_line_count ( ) const |
|
get_line_offset ( int line ) |
|
get_menu ( ) const |
|
get_paragraph_count ( ) const |
|
get_paragraph_offset ( int paragraph ) |
|
get_parsed_text ( ) const |
|
get_selected_text ( ) const |
|
get_selection_from ( ) const |
|
get_selection_to ( ) const |
|
get_total_character_count ( ) const |
|
get_v_scroll_bar ( ) |
|
get_visible_line_count ( ) const |
|
get_visible_paragraph_count ( ) const |
|
void |
install_effect ( Variant effect ) |
is_menu_visible ( ) const |
|
is_ready ( ) const |
|
void |
menu_option ( int option ) |
void |
newline ( ) |
void |
parse_bbcode ( String bbcode ) |
parse_expressions_for_values ( PackedStringArray expressions ) |
|
void |
pop ( ) |
void |
push_bgcolor ( Color bgcolor ) |
void |
push_bold ( ) |
void |
|
void |
push_cell ( ) |
void |
push_color ( Color color ) |
void |
push_customfx ( RichTextEffect effect, Dictionary env ) |
void |
push_dropcap ( String string, Font font, int size, Rect2 dropcap_margins=Rect2(0, 0, 0, 0), Color color=Color(1, 1, 1, 1), int outline_size=0, Color outline_color=Color(0, 0, 0, 0) ) |
void |
push_fgcolor ( Color fgcolor ) |
void |
|
void |
push_font_size ( int font_size ) |
void |
|
void |
push_indent ( int level ) |
void |
push_italics ( ) |
void |
|
void |
|
void |
push_mono ( ) |
void |
push_normal ( ) |
void |
push_outline_color ( Color color ) |
void |
push_outline_size ( int outline_size ) |
void |
push_paragraph ( HorizontalAlignment alignment, TextDirection base_direction=0, String language="", StructuredTextParser st_parser=0 ) |
void |
|
void |
push_table ( int columns, InlineAlignment inline_align=0, int align_to_row=-1 ) |
void |
push_underline ( ) |
remove_paragraph ( int paragraph ) |
|
void |
scroll_to_line ( int line ) |
void |
scroll_to_paragraph ( int paragraph ) |
void |
|
void |
select_all ( ) |
void |
set_cell_border_color ( Color color ) |
void |
set_cell_padding ( Rect2 padding ) |
void |
set_cell_row_background_color ( Color odd_row_bg, Color even_row_bg ) |
void |
set_cell_size_override ( Vector2 min_size, Vector2 max_size ) |
void |
set_table_column_expand ( int column, bool expand, int ratio ) |
Theme Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Signals¶
finished ( )
Triggered when the document is fully loaded.
meta_clicked ( Variant meta )
Triggered when the user clicks on content between meta tags. If the meta is defined in text, e.g. [url={"data"="hi"}]hi[/url]
, then the parameter for this signal will be a String type. If a particular type or an object is desired, the push_meta method must be used to manually insert the data into the tag stack.
meta_hover_ended ( Variant meta )
Triggers when the mouse exits a meta tag.
meta_hover_started ( Variant meta )
Triggers when the mouse enters a meta tag.
Enumerations¶
enum ListType:
ListType LIST_NUMBERS = 0
Each list item has a number marker.
ListType LIST_LETTERS = 1
Each list item has a letter marker.
ListType LIST_ROMAN = 2
Each list item has a roman number marker.
ListType LIST_DOTS = 3
Each list item has a filled circle marker.
Copies the selected text.
Selects the whole RichTextLabel text.
Represents the size of the MenuItems enum.
Property Descriptions¶
AutowrapMode autowrap_mode = 3
void set_autowrap_mode ( AutowrapMode value )
AutowrapMode get_autowrap_mode ( )
If set to something other than TextServer.AUTOWRAP_OFF, the text gets wrapped inside the node's bounding rectangle. To see how each mode behaves, see AutowrapMode.
bool bbcode_enabled = false
If true
, the label uses BBCode formatting.
If true
, a right-click displays the context menu.
Array custom_effects = []
The currently installed custom effects. This is an array of RichTextEffects.
To add a custom effect, it's more convenient to use install_effect.
bool deselect_on_focus_loss_enabled = true
If true
, the selected text will be deselected when focus is lost.
bool fit_content = false
If true
, the label's minimum size will be automatically updated to fit its content, matching the behavior of Label.
bool hint_underlined = true
If true
, the label underlines hint tags such as [hint=description]{text}[/hint]
.
String language = ""
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
bool meta_underlined = true
If true
, the label underlines meta tags such as [url]{text}[/url]
.
int progress_bar_delay = 1000
The delay after which the loading progress bar is displayed, in milliseconds. Set to -1
to disable progress bar entirely.
Note: Progress bar is displayed only if threaded is enabled.
bool scroll_active = true
If true
, the scrollbar is visible. Setting this to false
does not block scrolling completely. See scroll_to_line.
bool scroll_following = false
If true
, the window scrolls down to display new content automatically.
bool selection_enabled = false
If true
, the label allows text selection.
bool shortcut_keys_enabled = true
If true
, shortcut keys for context menu items are enabled, even if the context menu is disabled.
StructuredTextParser structured_text_bidi_override = 0
void set_structured_text_bidi_override ( StructuredTextParser value )
StructuredTextParser get_structured_text_bidi_override ( )
Set BiDi algorithm override for the structured text.
Array structured_text_bidi_override_options = []
void set_structured_text_bidi_override_options ( Array value )
Array get_structured_text_bidi_override_options ( )
Set additional options for BiDi override.
int tab_size = 4
The number of spaces associated with a single tab length. Does not affect \t
in text tags, only indent tags.
String 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.
Note: If bbcode_enabled is true
, it is unadvised to use the +=
operator with text
(e.g. text += "some string"
) as it replaces the whole text and can cause slowdowns. It will also erase all BBCode that was added to stack using push_*
methods. Use append_text for adding text instead, unless you absolutely need to close a tag that was opened in an earlier method call.
TextDirection text_direction = 0
void set_text_direction ( TextDirection value )
TextDirection get_text_direction ( )
Base text writing direction.
bool threaded = false
If true
, text processing is done in a background thread.
int visible_characters = -1
The number of characters to display. If set to -1
, all characters are displayed. This can be useful when animating the text appearing in a dialog box.
Note: Setting this property updates visible_ratio accordingly.
VisibleCharactersBehavior visible_characters_behavior = 0
void set_visible_characters_behavior ( VisibleCharactersBehavior value )
VisibleCharactersBehavior get_visible_characters_behavior ( )
Sets the clipping behavior when visible_characters or visible_ratio is set. See VisibleCharactersBehavior for more info.
float visible_ratio = 1.0
The fraction of characters to display, relative to the total number of characters (see get_total_character_count). If set to 1.0
, all characters are displayed. If set to 0.5
, only half of the characters will be displayed. This can be useful when animating the text appearing in a dialog box.
Note: Setting this property updates visible_characters accordingly.
Method Descriptions¶
void add_image ( Texture2D image, int width=0, int height=0, Color color=Color(1, 1, 1, 1), InlineAlignment inline_align=5, Rect2 region=Rect2(0, 0, 0, 0) )
Adds an image's opening and closing tags to the tag stack, optionally providing a width
and height
to resize the image, a color
to tint the image and a region
to only use parts of the image.
If width
or height
is set to 0, the image size will be adjusted in order to keep the original aspect ratio.
If width
and height
are not set, but region
is, the region's rect will be used.
void add_text ( String text )
Adds raw non-BBCode-parsed text to the tag stack.
void append_text ( String bbcode )
Parses bbcode
and adds tags to the tag stack as needed.
Note: Using this method, you can't close a tag that was opened in a previous 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 text instead of using append_text.
void clear ( )
Clears the tag stack and sets text to an empty string.
void deselect ( )
Clears the current selection.
int get_character_line ( int character )
Returns the line number of the character position provided.
Note: If threaded is enabled, this method returns a value for the loaded part of the document. Use is_ready or finished to determine whether document is fully loaded.
int get_character_paragraph ( int character )
Returns the paragraph number of the character position provided.