Class reference
TextLine
Inherits RefCounted
Holds a line of text.
Description
Abstraction over TextServer for handling a single line of text.
Properties
int alignment = 0
int alignment = 0Sets text alignment within the line as if the line was horizontal.
int direction = 0
int direction = 0Text writing direction.
String ellipsis_char = "…"
String ellipsis_char = "…"Ellipsis character used for text clipping.
int flags = 3
int flags = 3Line alignment rules. For more info see TextServer.
int orientation = 0
int orientation = 0Text orientation.
bool preserve_control = false
bool preserve_control = falseIf set to true text will display control characters.
bool preserve_invalid = true
bool preserve_invalid = trueIf set to true text will display invalid characters.
int text_overrun_behavior = 3
int text_overrun_behavior = 3The clipping behavior when the text exceeds the text line's set width.
float width = -1.0
float width = -1.0Text line width.
Methods
bool add_object(Variant key, Vector2 size, int inline_align = 5, int length = 1, float baseline = 0.0)
bool add_object(Variant key, Vector2 size, int 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)
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), float oversampling = 0.0) const
RID canvas, Vector2 pos, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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(RID canvas, Vector2 pos, int outline_size = 1, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) const
RID canvas, Vector2 pos, int outline_size = 1, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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.
int get_inferred_direction() const
int get_inferred_direction() constReturns the text writing direction inferred by the BiDi algorithm.
float get_line_ascent() const
float get_line_ascent() constReturns 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
float get_line_descent() constReturns 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
float get_line_underline_position() constReturns pixel offset of the underline below the baseline.
float get_line_underline_thickness() const
float get_line_underline_thickness() constReturns thickness of the underline.
float get_line_width() const
float get_line_width() constReturns width (for horizontal layout) or height (for vertical) of the text.
Rect2 get_object_rect(Variant key) const
Rect2 get_object_rect(Variant key) constReturns bounding rectangle of the inline object.
Array get_objects() const
Array get_objects() constReturns array of inline objects.
RID get_rid() const
RID get_rid() constReturns TextServer buffer RID.
Vector2 get_size() const
Vector2 get_size() constReturns size of the bounding box of the text.
int hit_test(float coords) const
int hit_test(float coords) constReturns caret character offset at the specified pixel offset at the baseline. This function always returns a valid position.
bool resize_object(Variant key, Vector2 size, int inline_align = 5, float baseline = 0.0)
bool resize_object(Variant key, Vector2 size, int inline_align = 5, float baseline = 0.0)Sets new size and alignment of embedded object.
void set_bidi_override(Array override)
Array override)Overrides BiDi for the structured text. Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately.
void tab_align(PackedFloat32Array tab_stops)
PackedFloat32Array tab_stops)Aligns text to the given tab-stops.