Skip to content

TextLine

Inherits: RefCounted < Object

Holds a line of text.

Abstraction over TextSystem for handling a single line of text.

Type Name Default
HorizontalAlignment alignment 0
TextSystem.Direction direction 0
String ellipsis_char "…"
BitField[TextSystem.JustificationFlag] flags 3
TextSystem.Orientation orientation 0
bool preserve_control false
bool preserve_invalid true
TextSystem.OverrunBehavior text_overrun_behavior 3
float width -1.0
Returns Method
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
TextSystem.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)

alignment

HorizontalAlignment alignment = 0

Sets text alignment within the line as if the line was horizontal.

direction

TextSystem.Direction direction = 0

Text writing direction.

ellipsis_char

String ellipsis_char = "…"

Ellipsis character used for text clipping.

flags

BitField[TextSystem.JustificationFlag] flags = 3

Line alignment rules. For more info see TextSystem.

orientation

TextSystem.Orientation orientation = 0

Text orientation.

preserve_control

bool preserve_control = false

If set to true text will display control characters.

preserve_invalid

bool preserve_invalid = true

If set to true text will display invalid characters.

text_overrun_behavior

TextSystem.OverrunBehavior text_overrun_behavior = 3

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

width

float width = -1.0

Text line width.

add_object

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

Adds inline object to the text buffer, key must be unique. In the text, object is represented as length object replacement characters.

add_string

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

Adds text span and font to draw it.

clear

void clear()

Clears text line (removes text and inline objects).

draw

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.

draw_outline

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.

duplicate

TextLine duplicate() const

Duplicates this TextLine.

get_inferred_direction

TextSystem.Direction get_inferred_direction() const

Returns the text writing direction inferred by the BiDi algorithm.

get_line_ascent

float get_line_ascent() const

Returns the text ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical).

get_line_descent

float get_line_descent() const

Returns the text descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical).

get_line_underline_position

float get_line_underline_position() const

Returns pixel offset of the underline below the baseline.

get_line_underline_thickness

float get_line_underline_thickness() const

Returns thickness of the underline.

get_line_width

float get_line_width() const

Returns width (for horizontal layout) or height (for vertical) of the text.

get_object_rect

Rect2 get_object_rect(key: Variant) const

Returns bounding rectangle of the inline object.

get_objects

Array get_objects() const

Returns array of inline objects.

get_rid

RID get_rid() const

Returns TextSystem buffer RID.

get_size

Vector2 get_size() const

Returns size of the bounding box of the text.

has_object

bool has_object(key: Variant) const

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

hit_test

int hit_test(coords: float) const

Returns caret character offset at the specified pixel offset at the baseline. This function always returns a valid position.

resize_object

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

Sets new size and alignment of embedded object.

set_bidi_override

void set_bidi_override(override: Array)

Overrides BiDi for the structured text.

Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately.

tab_align

void tab_align(tab_stops: PackedFloat32Array)

Aligns text to the given tab-stops.