Actor > Textfeld

Inhalt

Actor > Textfeld#

API Reference#

class miniworlds.actors.texts.textbox.TextBox(position, width, height, **kwargs)[Quellcode]

A multi-line text box with fixed width and height.

Long lines are automatically word-wrapped to fit within the given width. Each line is rendered as a separate Text actor.

Parameter:
  • position – Top-left position of the text box.

  • width – Width of the text box in pixels.

  • height – Maximum height of the text box in pixels.

  • text – Initial text to display (keyword argument).

  • font_size – Font size for all lines (keyword argument, default 18).

  • border – If truthy, a rectangle outline is drawn around the box.

Examples

from miniworlds import *
world = World(400, 300)
box = TextBox((10, 10), 380, 200, text="Hello World! This is a long text that wraps automatically.")
world.run()
__init__(position, width, height, **kwargs)[Quellcode]

Creates a text box with fixed width and height.

Parameter:
  • position – Top-left position of the text box.

  • width – Maximum width in pixels before text is wrapped.

  • height – Maximum height in pixels.

  • border – Optional keyword argument. If truthy, draw a rectangle around the text box.

  • font_size – Optional keyword argument. Font size used for all lines.

create_line(position, txt='')[Quellcode]

Creates a single Text actor for one rendered line.

Rückgabetyp:

Text

Parameter:
  • position – Top-left position of the line.

  • txt – Text content of the line. Defaults to an empty string.

Rückgabe:

The created text actor.

Rückgabetyp:

text.Text

create_line_actors()[Quellcode]

Builds the visible text lines for the current text box content.

The text is split line by line and then wrapped after words so that no rendered line becomes wider than self.line_width. Each line is stored as a child Text actor.

Examples

After changing self.text, call this method to rebuild all lines.