Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Label

Inherits: Control < CanvasItem < Node < Object

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.

教程

属性

AutowrapMode

autowrap_mode

0

bool

clip_text

false

HorizontalAlignment

horizontal_alignment

0

BitField<JustificationFlag>

justification_flags

163

LabelSettings

label_settings

String

language

""

int

lines_skipped

0

int

max_lines_visible

-1

MouseFilter

mouse_filter

2 (overrides Control)

BitField<SizeFlags>

size_flags_vertical

4 (overrides Control)

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

PackedFloat32Array

tab_stops

PackedFloat32Array()

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

float

visible_ratio

1.0

Methods

int

get_line_count ( ) const

int

get_line_height ( int line=-1 ) const

int

get_total_character_count ( ) const

int

get_visible_line_count ( ) const

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

AutowrapMode autowrap_mode = 0

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.


bool clip_text = false

  • void set_clip_text ( bool value )

  • bool is_clipping_text ( )

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


HorizontalAlignment horizontal_alignment = 0

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


BitField<JustificationFlag> justification_flags = 163

Line fill alignment rules. For more info see JustificationFlag.


LabelSettings label_settings

A LabelSettings resource that can be shared between multiple Label nodes. Takes priority over theme properties.


String language = ""

  • void set_language ( String value )

  • String get_language ( )

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


int lines_skipped = 0

  • void set_lines_skipped ( int value )

  • int get_lines_skipped ( )

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


int max_lines_visible = -1

  • void set_max_lines_visible ( int value )

  • int get_max_lines_visible ( )

Limits the lines of text the node shows on screen.


StructuredTextParser structured_text_bidi_override = 0

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.


PackedFloat32Array tab_stops = PackedFloat32Array()

Aligns text to the given tab-stops.


String text = ""

The text to display on screen.


TextDirection text_direction = 0

Base text writing direction.


OverrunBehavior text_overrun_behavior = 0

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


bool uppercase = false

  • void set_uppercase ( bool value )

  • bool is_uppercase ( )

If true, all the text displays as UPPERCASE.


VerticalAlignment vertical_alignment = 0

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


int visible_characters = -1

  • void set_visible_characters ( int value )

  • int get_visible_characters ( )

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

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


float visible_ratio = 1.0

  • void set_visible_ratio ( float value )

  • float get_visible_ratio ( )

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

int get_line_count ( ) const

Returns the number 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 are no lines, returns font size in pixels.


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.


Theme Property Descriptions

Color font_color = Color(1, 1, 1, 1)

Default text Color of the Label.


Color font_outline_color = Color(1, 1, 1, 1)

The color of text outline.


Color font_shadow_color = Color(0, 0, 0, 0)

Color of the text's shadow effect.


int line_spacing = 3

Vertical space between lines in multiline Label.


int outline_size = 0

Text outline size.

Note: If using a font with FontFile.multichannel_signed_distance_field enabled, its FontFile.msdf_pixel_range must be set to at least twice the value of outline_size for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.


int shadow_offset_x = 1

The horizontal offset of the text's shadow.


int shadow_offset_y = 1

The vertical offset of the text's shadow.


int shadow_outline_size = 1

The size of the shadow outline.


Font font

Font used for the Label's text.


int font_size

Font size of the Label's text.


StyleBox normal

Background StyleBox for the Label.