Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

TextLine

继承: RefCounted < Object

存放一行文本。

描述

基于 TextServer 的抽象,用于处理单行文本。

属性

HorizontalAlignment

alignment

0

Direction

direction

0

BitField<JustificationFlag>

flags

3

Orientation

orientation

0

bool

preserve_control

false

bool

preserve_invalid

true

OverrunBehavior

text_overrun_behavior

3

float

width

-1.0

方法

bool

add_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, int length=1, float baseline=0.0 )

bool

add_string ( String text, Font font, int font_size, String language="", Variant meta=null )

void

clear ( )

void

draw ( RID canvas, Vector2 pos, Color color=Color(1, 1, 1, 1) ) const

void

draw_outline ( RID canvas, Vector2 pos, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

float

get_line_ascent ( ) const

float

get_line_descent ( ) const

float

get_line_underline_position ( ) const

float

get_line_underline_thickness ( ) const

float

get_line_width ( ) const

Rect2

get_object_rect ( Variant key ) const

Array

get_objects ( ) const

RID

get_rid ( ) const

Vector2

get_size ( ) const

int

hit_test ( float coords ) const

bool

resize_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, float baseline=0.0 )

void

set_bidi_override ( Array override )

void

tab_align ( PackedFloat32Array tab_stops )


属性说明

HorizontalAlignment alignment = 0

设置行内的文本对齐方式,始终按照该行为横向的情况设置。


Direction direction = 0

文本书写方向。


BitField<JustificationFlag> flags = 3

行对齐规则。详细请参阅 TextServer


Orientation orientation = 0

文本朝向。


bool preserve_control = false

  • void set_preserve_control ( bool value )

  • bool get_preserve_control ( )

如果设置为 true,则将在文本中显示控制字符。


bool preserve_invalid = true

  • void set_preserve_invalid ( bool value )

  • bool get_preserve_invalid ( )

如果设置为 true,则将在文本中显示无效字符。


OverrunBehavior text_overrun_behavior = 3

设置文本超出文本行的设置宽度时的裁剪行为。有关所有模式的描述,请参阅 OverrunBehavior


float width = -1.0

  • void set_width ( float value )

  • float get_width ( )

文本行宽。


方法说明

bool add_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, int length=1, float baseline=0.0 )

向文本缓冲中添加内联对象,key 必须唯一。在文本中,对象使用 length 个对象替换字符表示。


bool add_string ( String text, Font font, int font_size, String language="", Variant meta=null )

添加文本区间以及用于绘制的字体。


void clear ( )

清除文本行(移除文本和内联对象)。


void draw ( RID canvas, Vector2 pos, Color color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制文本,颜色为 colorpos 指定的是边界框的左上角。


void draw_outline ( RID canvas, Vector2 pos, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制文本,颜色为 colorpos 指定的是边界框的左上角。


float get_line_ascent ( ) const

返回该文本的升部(水平排版时为基线上方的像素数,垂直排版时为基线左侧的像素数)。


float get_line_descent ( ) const

返回该文本的降部(水平排版时为基线下方的像素数,垂直排版时为基线右侧的像素数)。


float get_line_underline_position ( ) const

返回基线下方下划线的像素偏移。


float get_line_underline_thickness ( ) const

返回下划线的粗细度。


float get_line_width ( ) const

返回文本的宽度(对于水平排版)或高度(对于垂直排版)。


Rect2 get_object_rect ( Variant key ) const

返回内联对象的边界矩形。


Array get_objects ( ) const

返回内联对象的数组。


RID get_rid ( ) const

返回 TextServer 缓冲区 RID。


Vector2 get_size ( ) const

返回文本边界框的大小。


int hit_test ( float coords ) const

返回基线处指定像素偏移处的文本光标的偏移量。该函数始终返回一个有效位置。


bool resize_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, float baseline=0.0 )

设置嵌入对象的新大小和对齐方式。


void set_bidi_override ( Array override )

覆盖用于结构化文本的 BiDi。

覆盖范围应覆盖完整的源文本而没有重叠。BiDi 算法将分别被用于每个范围。


void tab_align ( PackedFloat32Array tab_stops )

将文本与给定的制表位对齐。