gale.ui.text_box module
This file contains the implementation of the classes TextBox, a paginated block of text advanced by click/Enter (RPG-dialogue style), and PaginatedTextBox, the same paginated text but navigated with explicit Previous/Next buttons instead.
Author: Alejandro Mujica (aledrums@gmail.com)
- class gale.ui.text_box.TextBox(x, y, width, height, text, font=None, lines_per_page=3, on_close=None, theme=None)[source]
Bases:
WidgetA paginated block of text, such as dialogue or an in-game hint. advance() moves to the next page (on a mouse click or on_confirm), or, on the last page, hides the box and calls on_close. This is the click-or-Enter-to-continue style used by RPG dialogue, where the player doesn’t need to navigate backward.
For content the player pages through with explicit “Previous”/”Next” buttons instead (e.g. a rules or help screen), use next_page() and previous_page() directly, or wrap this in a PaginatedTextBox, which also wires up and enables/disables those buttons for you.
- Parameters:
x (float)
y (float)
width (float)
height (float)
text (str)
font (Font | None)
lines_per_page (int)
on_close (Callable[[], None] | None)
theme (Theme | None)
- property finished: bool
- property page_count: int
- property has_next_page: bool
- property has_previous_page: bool
- next_page()[source]
Move to the next page, if any, without the auto-close behavior of advance(). Meant to back a “Next” button.
- Returns:
Whether there was a next page to move to.
- Return type:
bool
- previous_page()[source]
Move back to the previous page, if any. Meant to back a “Previous” button.
- Returns:
Whether there was a previous page to move back to.
- Return type:
bool
- on_mouse_click(position, data)[source]
- Parameters:
position (Tuple[float, float])
data (MouseClickData)
- Return type:
bool
- class gale.ui.text_box.PaginatedTextBox(x, y, width, height, text, font=None, lines_per_page=3, button_height=28, button_width=96, previous_label='Previous', next_label='Next', theme=None, visible=True)[source]
Bases:
ContainerA TextBox paired with “Previous”/”Next” buttons docked under it, for content the player pages through at their own pace instead of a click/Enter-to-continue dialogue (e.g. an instructions or help screen). The buttons are kept in sync every update(): disabled on the first/last page instead of wrapping around, and this never auto-hides itself the way TextBox.advance() does on its own — close it explicitly (e.g. from a Window’s close button) if needed.
Usage example:
help_box = PaginatedTextBox(160, 90, 320, 220, long_help_text)
- Parameters:
x (float)
y (float)
width (float)
height (float)
text (str)
font (Font | None)
lines_per_page (int)
button_height (int)
button_width (int)
previous_label (str)
next_label (str)
theme (Theme | None)
visible (bool)