Label
继承: 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.
属性
方法
Rect2 | get_character_bounds ( pos: int ) const1 |
int | get_line_count ( ) const1 |
int | get_line_height ( line: int = -1 ) const1 |
int | get_total_character_count ( ) const1 |
int | get_visible_line_count ( ) const1 |
主题属性
Color | font_color |
Color | font_outline_color |
Color | font_shadow_color |
int | line_spacing |
int | outline_size |
int | shadow_offset_x |
int | shadow_offset_y |
int | shadow_outline_size |
Font | font |
int | font_size |
StyleBox | normal |
属性说明
AutowrapMode autowrap_mode = 0
void
set_autowrap_mode ( value: AutowrapMode )- AutowrapMode 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.
bool
clip_text = false
If true
, the Label only shows the text that fits inside its bounding rectangle and will clip text horizontally.
String
ellipsis_char = "…"
Ellipsis character used for text clipping.
HorizontalAlignment horizontal_alignment = 0
void
set_horizontal_alignment ( value: HorizontalAlignment )- HorizontalAlignment 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.
JustificationFlag justification_flags = 163
void
set_justification_flags ( value: JustificationFlag )- JustificationFlag get_justification_flags ( )
Line fill alignment rules. See JustificationFlag for more information.
LabelSettings
label_settings
void
set_label_settings ( value:LabelSettings
)LabelSettings
get_label_settings ( )
A LabelSettings
resource that can be shared between multiple Label nodes. Takes priority over theme properties.
String
language = ""
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
int
lines_skipped = 0
The number of the lines ignored and not displayed from the start of the text
value.
int
max_lines_visible = -1
Limits the lines of text the node shows on screen.
StructuredTextParser structured_text_bidi_override = 0
void
set_structured_text_bidi_override ( value: StructuredTextParser )- 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 ( value:Array
)Array
get_structured_text_bidi_override_options ( )
Set additional options for BiDi override.
PackedFloat32Array
tab_stops = PackedFloat32Array()
void
set_tab_stops ( value:PackedFloat32Array
)PackedFloat32Array
get_tab_stops ( )
Aligns text to the given tab-stops.
Note: The returned array is copied and any changes to it will not update the original property value. See PackedFloat32Array
for more details.
String
text = ""
The text to display on screen.
TextDirection text_direction = 0
void
set_text_direction ( value: TextDirection )- TextDirection get_text_direction ( )
Base text writing direction.
OverrunBehavior text_overrun_behavior = 0
void
set_text_overrun_behavior ( value: OverrunBehavior )- OverrunBehavior 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.
bool
uppercase = false
If true
, all the text displays as UPPERCASE.
VerticalAlignment vertical_alignment = 0
void
set_vertical_alignment ( value: VerticalAlignment )- VerticalAlignment 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 = -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 ( value: VisibleCharactersBehavior )- 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.
方法说明
Rect2
get_character_bounds ( pos: int
) const1
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.
Returns the number of lines of text the Label has.
int
get_line_height ( line: int
= -1 ) const1
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 ( ) const1
Returns the total number of printable characters in the text (excluding spaces and newlines).
int
get_visible_line_count ( ) const1
Returns the number of lines shown. Useful if the Label's height cannot currently display all lines.
主题属性说明
Color
font_color = Color(1, 1, 1, 1)
Default text Color
of the Label.
Color
font_outline_color = Color(0, 0, 0, 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.
Note: Using a value that is larger than half the font size is not recommended, as the font outline may fail to be fully closed in this case.
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.
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。