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.

TextLine

繼承: RefCounted < Object

存放一行文字。

說明

基於 TextServer 的抽象,用於處理單行文字。

屬性

HorizontalAlignment

alignment

0

Direction

direction

0

String

ellipsis_char

"…"

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(key: Variant, size: Vector2, inline_align: InlineAlignment = 5, length: int = 1, baseline: float = 0.0)

bool

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

void

clear()

void

draw(canvas: RID, pos: Vector2, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

void

draw_outline(canvas: RID, pos: Vector2, outline_size: int = 1, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

TextLine

duplicate() const

Direction

get_inferred_direction() 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(key: Variant) const

Array

get_objects() const

RID

get_rid() const

Vector2

get_size() const

bool

has_object(key: Variant) const

int

hit_test(coords: float) const

bool

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

void

set_bidi_override(override: Array)

void

tab_align(tab_stops: PackedFloat32Array)


屬性說明

HorizontalAlignment alignment = 0 🔗

設定行內的文字對齊方式,始終按照該行為橫向的情況設定。


Direction direction = 0 🔗

文字書寫方向。


String ellipsis_char = "…" 🔗

  • void set_ellipsis_char(value: String)

  • String get_ellipsis_char()

Ellipsis character used for text clipping.


BitField[JustificationFlag] flags = 3 🔗

行對齊規則。詳細請參閱 TextServer


Orientation orientation = 0 🔗

文字朝向。


bool preserve_control = false 🔗

  • void set_preserve_control(value: bool)

  • bool get_preserve_control()

如果設定為 true,則將在文字中顯示控制字元。


bool preserve_invalid = true 🔗

  • void set_preserve_invalid(value: bool)

  • bool get_preserve_invalid()

如果設定為 true,則將在文字中顯示無效字元。


OverrunBehavior text_overrun_behavior = 3 🔗

The clipping behavior when the text exceeds the text line's set width.


float width = -1.0 🔗

文字行寬。


方法說明

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

向文字緩衝中新增行內物件,key 必須唯一。在文字中,物件使用 length 個物件替換字元表示。


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

新增文字區間以及用於繪製的字形。


void clear() 🔗

清除文字行(移除文字和行內物件)。


void draw(canvas: RID, pos: Vector2, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw text into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


void draw_outline(canvas: RID, pos: Vector2, outline_size: int = 1, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw text into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


TextLine duplicate() const 🔗

Duplicates this TextLine.


Direction get_inferred_direction() const 🔗

Returns the text writing direction inferred by the BiDi algorithm.


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(key: Variant) const 🔗

返回行內對象的邊界矩形。


Array get_objects() const 🔗

返回行內物件的陣列。


RID get_rid() const 🔗

返回 TextServer 緩衝區 RID。


Vector2 get_size() const 🔗

返回文字邊界框的大小。


bool has_object(key: Variant) const 🔗

Returns true if an object with key is embedded in this line.


int hit_test(coords: float) const 🔗

返回基線處指定圖元偏移處的文字游標的偏移量。該函式始終返回一個有效位置。


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

設定內嵌物件的新大小和對齊方式。


void set_bidi_override(override: Array) 🔗

覆蓋用於結構化文字的 BiDi。

覆蓋範圍應覆蓋完整的源文字而沒有重疊。BiDi 演算法將分別被用於每個範圍。


void tab_align(tab_stops: PackedFloat32Array) 🔗

將文字與給定的定位停駐點對齊。