Label
Inherits: Control < CanvasItem < Entity < Object
Description
Section titled “Description”A control for displaying plain text.
A control for displaying plain text. 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 rich text formatting. For that, use RichTextLabel instead.
Note: A single Label node is not designed to display huge amounts of text. To display large amounts of text in a single node, consider using RichTextLabel instead as it supports features like an integrated scroll bar and threading. RichTextLabel generally performs better when displaying large amounts of text (several pages or more).
Properties
Section titled “Properties”Methods
Section titled “Methods”| Returns | Method |
|---|---|
| Rect2 | get_character_bounds(pos: int) const |
| int | get_line_count() const |
| int | get_line_height(line: int = -1) const |
| int | get_rendered_font_size() const |
| int | get_total_character_count() const |
| int | get_visible_line_count() const |
Theme items
Section titled “Theme items”font_color
Color font_color (color) = Color(1, 1, 1, 1)
font_outline_color
Color font_outline_color (color) = Color(0, 0, 0, 1)
font_shadow_color
Color font_shadow_color (color) = Color(0, 0, 0, 0)
line_spacing
int line_spacing (constant) = 3
outline_size
int outline_size (constant) = 0
paragraph_spacing
int paragraph_spacing (constant) = 0
shadow_offset_x
int shadow_offset_x (constant) = 1
shadow_offset_y
int shadow_offset_y (constant) = 1
shadow_outline_size
int shadow_outline_size (constant) = 1
font
Font font (font)
font_size
int font_size (font_size)
focus
StyleBox focus (style)
normal
StyleBox normal (style)
Property descriptions
Section titled “Property descriptions”autowrap_mode
TextSystem.AutowrapMode autowrap_mode = 0
If set to something other than TextSystem.AUTOWRAP_OFF, the text gets wrapped inside the node’s bounding rectangle. If you resize the node, it will change its height automatically to show all the text.
Note: Labels with autowrapping enabled must have a custom maximum width configured to work correctly, either through the Label’s own Control.custom_maximum_size or as a result of a propagated maximum size from a parent Control with Control.propagate_maximum_size enabled.
autowrap_trim_flags
BitField[TextSystem.LineBreakFlag] autowrap_trim_flags = 192
Autowrap space trimming flags. See TextSystem.BREAK_TRIM_START_EDGE_SPACES and TextSystem.BREAK_TRIM_END_EDGE_SPACES for more info.
clip_text
bool clip_text = false
If true, the Label only shows the text that fits inside its bounding rectangle and will clip text horizontally.
ellipsis_char
String ellipsis_char = "…"
Ellipsis character used for text clipping.
horizontal_alignment
HorizontalAlignment horizontal_alignment = 0
Controls the text’s horizontal alignment. Supports left, center, right, and fill (also known as justify).
justification_flags
BitField[TextSystem.JustificationFlag] justification_flags = 163
Line fill alignment rules.
label_settings
LabelSettings label_settings
A LabelSettings resource that can be shared between multiple Label nodes. Takes priority over theme properties.
language
String language = ""
Language code used for line-breaking and text shaping algorithms. If left empty, the current locale is used instead.
lines_skipped
int lines_skipped = 0
The number of the lines ignored and not displayed from the start of the text value.
max_lines_visible
int max_lines_visible = -1
Limits the lines of text the node shows on screen.
maximum_font_size
int maximum_font_size = 60
The maximum font size used when resize_font_to_fit is enabled. If minimum_font_size is greater than maximum_font_size, the minimum font size takes precedence.
minimum_font_size
int minimum_font_size = 10
The minimum font size used when resize_font_to_fit is enabled. Also determines the minimum vertical size of this Label, potentially used by a parent Container. If minimum_font_size is greater than maximum_font_size, the minimum font size takes precedence.
paragraph_separator
String paragraph_separator = "\\n"
String used as a paragraph separator. Each paragraph is processed independently, in its own BiDi context.
resize_font_to_fit
bool resize_font_to_fit = false
If true, the text size will automatically shrink or grow to fit within the node’s bounding rectangle. It will pick the largest font size between minimum_font_size and maximum_font_size that doesn’t cause the text to be truncated.
structured_text_bidi_override
TextSystem.StructuredTextParser structured_text_bidi_override = 0
Set BiDi algorithm override for the structured text.
structured_text_bidi_override_options
Array structured_text_bidi_override_options = []
Set additional options for BiDi override.
tab_stops
PackedFloat32Array tab_stops = PackedFloat32Array()
Aligns text to the given tab-stops.
text
String text = ""
The text to display on screen.
text_direction
Control.TextDirection text_direction = 0
Base text writing direction.
text_overrun_behavior
TextSystem.OverrunBehavior text_overrun_behavior = 0
The clipping behavior when the text exceeds the node’s bounding rectangle.
uppercase
bool uppercase = false
If true, all the text displays as UPPERCASE.
vertical_alignment
VerticalAlignment vertical_alignment = 0
Controls the text’s vertical alignment. Supports top, center, bottom, and fill.
visible_characters
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.
Note: Characters are counted as Unicode codepoints. A single visible grapheme may contain multiple codepoints (e.g. certain emoji use three codepoints). A single codepoint may contain two UTF-16 characters, which are used in C# strings.
visible_characters_behavior
TextSystem.VisibleCharactersBehavior visible_characters_behavior = 0
The clipping behavior when visible_characters or visible_ratio is set.
visible_ratio
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
Section titled “Method descriptions”get_character_bounds
Rect2 get_character_bounds(pos: int) const
Returns the bounding rectangle of the character at position pos in the label’s local coordinate system. If the character is a non-visual character or pos is outside the valid range, an empty Rect2 is returned. If the character is a part of a composite grapheme, the bounding rectangle of the whole grapheme is returned.
get_line_count
int get_line_count() const
Returns the number of lines of text the Label has.
get_line_height
int get_line_height(line: int = -1) const
Returns the height of the line line.
If line is set to -1, returns the biggest line height.
If there are no lines, returns font size in pixels.
get_rendered_font_size
int get_rendered_font_size() const
Returns the font size that is currently used for rendering. When resize_font_to_fit is enabled, this returns the automatically calculated font size. Otherwise, it returns the theme font size.
get_total_character_count
int get_total_character_count() const
Returns the total number of printable characters in the text (excluding spaces and newlines).
get_visible_line_count
int get_visible_line_count() const
Returns the number of lines shown. Useful if the Label’s height cannot currently display all lines.
