Up to date

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

TextLine

Inherits: RefCounted < Object

Holds a line of text.

Description

Abstraction over TextServer for handling a single line of text.

Properties

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

Methods

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 )


Property Descriptions

HorizontalAlignment alignment = 0

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


Direction direction = 0

Text writing direction.


BitField<JustificationFlag> flags = 3

Line alignment rules. For more info see TextServer.


Orientation orientation = 0

Text orientation.


bool preserve_control = false

  • void set_preserve_control ( bool value )

  • bool get_preserve_control ( )

If set to true text will display control characters.


bool preserve_invalid = true

  • void set_preserve_invalid ( bool value )

  • bool get_preserve_invalid ( )

If set to true text will display invalid characters.


OverrunBehavior text_overrun_behavior = 3

Sets the clipping behavior when the text exceeds the text line's set width. See OverrunBehavior for a description of all modes.


float width = -1.0

  • void set_width ( float value )

  • float get_width ( )

Text line width.


Method Descriptions

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

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


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

Adds text span and font to draw it.


void clear ( )

Clears text line (removes text and inline objects).


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

Draw text into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box.


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

Draw text into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box.


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).


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).


float get_line_underline_position ( ) const

Returns pixel offset of the underline below the baseline.


float get_line_underline_thickness ( ) const

Returns thickness of the underline.