Label¶
用于显示纯文本的控件。
描述¶
用于显示纯文本的控件。它使您可以控制水平和垂直对齐,并可以将文本包裹在节点的边界矩形内。它不支持粗体、斜体或其他富文本格式。为此,请改用RichTextLabel。
属性¶
|
||
|
||
|
||
|
||
BitField[JustificationFlag] |
|
|
|
||
|
||
|
||
mouse_filter |
|
|
|
||
BitField[SizeFlags] |
size_flags_vertical |
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法¶
get_character_bounds(pos: int) const |
|
get_line_count() const |
|
get_line_height(line: int = -1) const |
|
get_total_character_count() const |
|
get_visible_line_count() const |
主题属性¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
属性说明¶
AutowrapMode autowrap_mode = 0 🔗
void set_autowrap_mode(value: AutowrapMode)
AutowrapMode get_autowrap_mode()
如果设置为TextServer.AUTOWRAP_OFF以外的值,则文本将被包裹在节点的边界矩形内。如果调整节点的大小,它将自动更改其高度以显示所有文本。要查看每个模式的行为,请参阅AutowrapMode。
如果true,则标签仅显示适合其边界矩形的文本,并将水平剪辑文本。
用于文本剪辑的省略号字符。
HorizontalAlignment horizontal_alignment = 0 🔗
void set_horizontal_alignment(value: HorizontalAlignment)
HorizontalAlignment get_horizontal_alignment()
控制文本的水平对齐方式。支持左、中、右和填充或对齐。将其设置为HorizontalAlignment常量之一。
BitField[JustificationFlag] justification_flags = 163 🔗
void set_justification_flags(value: BitField[JustificationFlag])
BitField[JustificationFlag] get_justification_flags()
行填充对齐规则。有关详细信息,请参阅JustificationFlag。
LabelSettings label_settings 🔗
void set_label_settings(value: LabelSettings)
LabelSettings get_label_settings()
可以在多个Label节点之间共享的LabelSettings资源。优先于主题属性。
用于换行和文本整形算法的语言代码,如果留空则使用当前语言环境。
从text值开始忽略且未显示的行数。
限制节点在屏幕上显示的文本行。
String paragraph_separator = "\\n" 🔗
用作段落分隔符的字符串。每个段落在其自己的BiDi上下文中独立处理。
StructuredTextParser structured_text_bidi_override = 0 🔗
void set_structured_text_bidi_override(value: StructuredTextParser)
StructuredTextParser get_structured_text_bidi_override()
为结构化文本设置BiDi算法覆盖。
Array structured_text_bidi_override_options = [] 🔗
void set_structured_text_bidi_override_options(value: Array)
Array get_structured_text_bidi_override_options()
为BiDi覆盖设置附加选项。
PackedFloat32Array tab_stops = PackedFloat32Array() 🔗
void set_tab_stops(value: PackedFloat32Array)
PackedFloat32Array get_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.
要在屏幕上显示的文本。
TextDirection text_direction = 0 🔗
void set_text_direction(value: TextDirection)
TextDirection get_text_direction()
基本文本写作方向。
OverrunBehavior text_overrun_behavior = 0 🔗
void set_text_overrun_behavior(value: OverrunBehavior)
OverrunBehavior get_text_overrun_behavior()
设置文本超过节点边界矩形时的裁剪行为。有关所有模式的描述,请参阅OverrunBehavior。
如果true,则所有文本显示为大写。
VerticalAlignment vertical_alignment = 0 🔗
void set_vertical_alignment(value: VerticalAlignment)
VerticalAlignment get_vertical_alignment()
控制文本的垂直对齐方式。支持顶部、中心、底部和填充。将其设置为VerticalAlignment常量之一。
要显示的字符数。如果设置为-1,则显示所有字符。这在对话框中出现的文本进行动画处理时很有用。
注意:设置此属性会相应地更新visible_ratio。
VisibleCharactersBehavior visible_characters_behavior = 0 🔗
void set_visible_characters_behavior(value: VisibleCharactersBehavior)
VisibleCharactersBehavior get_visible_characters_behavior()
设置visible_characters或visible_ratio时的剪辑行为。有关详细信息,请参阅VisibleCharactersBehavior。
要显示的字符的比例,相对于字符总数(参见get_total_character_count())。如果设置为1.0,则显示所有字符。如果设置为0.5,则仅显示一半字符。这在对话框中出现的文本进行动画设置时非常有用。
注意:设置此属性会相应地更新visible_characters。
方法说明¶
Rect2 get_character_bounds(pos: int) const 🔗
返回标签本地坐标系中位置pos处字符的边界矩形。如果字符是非可视字符或pos在有效范围之外,则返回空的Rect2。如果字符是复合字位的一部分,则返回整个字位的边界矩形。
返回Label具有的文本行数。
int get_line_height(line: int = -1) const 🔗
返回线line的高度。
如果line设置为-1,则返回最大行高。
如果没有线条,则返回以像素为单位的字体大小。
int get_total_character_count() const 🔗
返回文本中可打印字符的总数(不包括空格和换行符)。
int get_visible_line_count() const 🔗
返回显示的行数。如果Label的高度当前无法显示所有行,则很有用。
主题属性说明¶
Color font_color = Color(1, 1, 1, 1) 🔗
Label的默认文本Color。
Color font_outline_color = Color(0, 0, 0, 1) 🔗
文本轮廓的颜色。
Color font_shadow_color = Color(0, 0, 0, 0) 🔗
Color文本的阴影效果。
行间距增加(以像素为单位),行间距增加到行下降。这个值可以是负数。
文本大纲大小。
注意:如果使用启用了FontFile.multichannel_signed_distance_field的字体,则其FontFile.msdf_pixel_range必须设置为至少两倍outline_size的值才能使轮廓渲染看起来正确。否则,轮廓可能会比预期的更早被切断。
注意:不建议使用大于字体大小一半的值,因为在这种情况下字体轮廓可能无法完全关闭。
段落之间的垂直空间。添加在line_spacing之上。
文本阴影的水平偏移量。
文本阴影的垂直偏移量。
阴影轮廓的大小。
Font用于Label的文本。
Label文本的字体大小。
Label的背景StyleBox。