Text

A text object for rendering text to the active renderer.

Constructor

A text object for rendering text to the active renderer.

Properties


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

Methods


Draw

draw(pos: Any = None, anchor: Any = None) 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.

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.

Set Font

set_font(font: Font) None

Set the font to use for rendering this text.

Args

  • font : The font to use.