Label

Inherits: Control < CanvasItem < Node < Object

Displays plain text in a line or wrapped inside a rectangle. For formatted text, use RichTextLabel.

Description

Label displays plain text on the screen. 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 formatting. For that, use RichTextLabel instead.

Note: Contrarily to most other Controls, Label's Control.mouse_filter defaults to Control.MOUSE_FILTER_IGNORE (i.e. it doesn't react to mouse input events). This implies that a label won't display any configured Control.hint_tooltip, unless you change its mouse filter.

Tutorials

Properties

AutowrapMode

autowrap_mode

0

bool

clip_text

false

HorizontalAlignment

horizontal_alignment

0

String

language

""

int

lines_skipped

0

int

max_lines_visible

-1

MouseFilter

mouse_filter

2 (overrides Control)

float

percent_visible

1.0

int

size_flags_vertical

4 (overrides Control)

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

String

text

""

TextDirection

text_direction

0

OverrunBehavior

text_overrun_behavior

0

bool

uppercase

false

VerticalAlignment

vertical_alignment

0

int

visible_characters

-1

VisibleCharactersBehavior

visible_characters_behavior

0

Methods

void

clear_opentype_features ( )

int

get_line_count ( ) const

int

get_line_height ( int line=-1 ) const

int

get_opentype_feature ( String tag ) const

int

get_total_character_count ( ) const

int

get_visible_line_count ( ) const

void

set_opentype_feature ( String tag, int value )

Theme Properties

Color

font_color

Color(1, 1, 1, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_shadow_color

Color(0, 0, 0, 0)

int

line_spacing

3

int

outline_size

0

int

shadow_offset_x

1

int

shadow_offset_y

1

int

shadow_outline_size

1

Font

font

int

font_size

StyleBox

normal

Property Descriptions

Default

0

Setter

set_autowrap_mode(value)

Getter

get_autowrap_mode()

If set to something other than TextServer.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. To see how each mode behaves, see AutowrapMode.


Default

false

Setter

set_clip_text(value)

Getter

is_clipping_text()

If true, the Label only shows the text that fits inside its bounding rectangle and will clip text horizontally.


Default

0

Setter

set_horizontal_alignment(value)

Getter

get_horizontal_alignment()

Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the HorizontalAlignment constants.


Default

""

Setter

set_language(value)

Getter

get_language()

Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.


  • int lines_skipped

Default

0

Setter

set_lines_skipped(value)

Getter

get_lines_skipped()

The node ignores the first lines_skipped lines before it starts to display text.


  • int max_lines_visible

Default

-1

Setter

set_max_lines_visible(value)

Getter

get_max_lines_visible()

Limits the lines of text the node shows on screen.


Default

1.0

Setter

set_percent_visible(value)

Getter

get_percent_visible()

Limits the amount of visible characters. If you set percent_visible to 0.5, only up to half of the text's characters will display on screen. Useful to animate the text in a dialog box.

Note: Setting this property updates visible_characters based on current get_total_character_count.


Default

0

Setter

set_structured_text_bidi_override(value)

Getter

get_structured_text_bidi_override()

Set BiDi algorithm override for the structured text.


  • Array structured_text_bidi_override_options

Default

[]

Setter

set_structured_text_bidi_override_options(value)

Getter

get_structured_text_bidi_override_options()

Set additional options for BiDi override.


Default

""

Setter

set_text(value)

Getter

get_text()

The text to display on screen.


Default

0

Setter

set_text_direction(value)

Getter

get_text_direction()

Base text writing direction.


Default

0

Setter

set_text_overrun_behavior(value)

Getter

get_text_overrun_behavior()

Sets the clipping behavior when the text exceeds the node's bounding rectangle. See OverrunBehavior for a description of all modes.


Default

false

Setter

set_uppercase(value)

Getter

is_uppercase()

If true, all the text displays as UPPERCASE.


Default

0

Setter

set_vertical_alignment(value)

Getter

get_vertical_alignment()

Controls the text's vertical alignment. Supports top, center, bottom, and fill. Set it to one of the VerticalAlignment constants.


  • int visible_characters

Default

-1

Setter

set_visible_characters(value)

Getter

get_visible_characters()

Restricts the number of characters to display. Set to -1 to disable.

Note: Setting this property updates percent_visible based on current get_total_character_count.


Default

0

Setter

set_visible_characters_behavior(value)

Getter

get_visible_characters_behavior()

Sets the clipping behavior when visible_characters or percent_visible is set. See VisibleCharactersBehavior for more info.

Method Descriptions

  • void clear_opentype_features ( )

Removes all OpenType features.


  • int get_line_count ( ) const

Returns the amount of lines of text the Label has.


  • int get_line_height ( int line=-1 ) const

Returns the height of the line line.

If line is set to -1, returns the biggest line height.

If there're no lines returns font size in pixels.


  • int get_opentype_feature ( String tag ) const

Returns OpenType feature tag.


  • int get_total_character_count ( ) const

Returns the total number of printable characters in the text (excluding spaces and newlines).


  • int get_visible_line_count ( ) const

Returns the number of lines shown. Useful if the Label's height cannot currently display all lines.


  • void set_opentype_feature ( String tag, int value )

Returns OpenType feature tag. More info: OpenType feature tags.

Theme Property Descriptions

Default

Color(1, 1, 1, 1)

Default text Color of the Label.


  • Color font_outline_color

Default

Color(1, 1, 1, 1)

The tint of Font's outline.


  • Color font_shadow_color

Default

Color(0, 0, 0, 0)

Color of the text's shadow effect.


  • int line_spacing

Default

3

Vertical space between lines in multiline Label.


  • int outline_size

Default

0

Text outline size.


  • int shadow_offset_x

Default

1

The horizontal offset of the text's shadow.


  • int shadow_offset_y

Default

1

The vertical offset of the text's shadow.


  • int shadow_outline_size

Default

1

The size of the shadow outline.


Font used for the Label's text.


  • int font_size

Font size of the Label's text.


Background StyleBox for the Label.