mini_arcade_pygame_backend.ports.text

Text port implementation for the native backend. Provides functionality to draw and measure text.

Classes

TextPort

Text port for the Mini Arcade native backend.

Module Contents

class mini_arcade_pygame_backend.ports.text.TextPort(window: mini_arcade_pygame_backend.ports.window.WindowPort, vp: mini_arcade_core.backend.viewport.ViewportTransform, font_path: str | None = None)

Text port for the Mini Arcade native backend.

Parameters:
  • native_backend (native.Backend) – The native backend instance.

  • vp (ViewportTransform) – The viewport transform.

  • font_path (str | None) – The path to the font file to use for text rendering.

measure(text: str, font_size: int | None = None) tuple[int, int]

Measure the width and height of the given text.

Parameters:
  • text (str) – The text to measure.

  • font_size (int | None) – The font size to use for measurement.

Returns:

A tuple containing the width and height of the text.

Return type:

tuple[int, int]

draw(x: int, y: int, text: str, color=(255, 255, 255), font_size: int | None = None)

Draw the given text at the specified position.

Parameters:
  • x (int) – The x-coordinate to draw the text.

  • y (int) – The y-coordinate to draw the text.

  • text (str) – The text to draw.

  • color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the text as an (R, G, B) or (R, G, B, A) tuple.

  • font_size (int | None) – The font size to use for drawing.