Text

A text object for rendering text to the active renderer.

Constructor

  • Text(font: Font, text: str = '') Text

A text object for rendering text to the active renderer.

Properties


NameDescriptionType
shadow_colorGet or set the shadow color for the text.Color
shadow_offsetGet or set the shadow offset for the text.Vec2
wrap_widthGet or set the wrap width in pixels for text wrapping.int
textGet or set the text string to be rendered.str
colorGet or set the color of the rendered text.Color
sizeGet the size (width, height) of the current text as a Vec2.Vec2
widthGet the width in pixels of the current text.int
heightGet the height in pixels of the current text.int

Methods


Draw

draw(pos: Vec2 = ..., anchor: Vec2 = ...) None

Draw the text to the renderer at the specified position with alignment. A shadow is drawn if shadow_color.a > 0 and shadow_offset is not (0, 0).

Args

  • pos : The position in pixels. Defaults to (0, 0).
  • anchor : The anchor point for alignment (0.0-1.0). Defaults to top left (0, 0).

Raises

  • RuntimeError : If the renderer is not initialized or text drawing fails.
  • RuntimeError : If the text font is not set or has gone out of scope.

Set Font

set_font(font: Font) None

Set the font to use for rendering this text.

Args

  • font : The font to use.

Get Rect

get_rect() Rect

Get the bounding rectangle of the current text.

Returns

Rect : A rectangle with x=0, y=0, and width/height of the text.