gale.ui.text_input module

This file contains the implementation of the class TextInput: a single-line editable text field (a player name, a chat message, a join code) driven by raw keyboard events.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.ui.text_input.TextInput(x, y, width, height, initial_text='', max_length=None, font=None, on_submit=None, theme=None)[source]

Bases: Widget

A single-line editable text field, for things like a player name, a chat message, or a server address/join code. Needs raw keyboard events rather than the confirm/navigate vocabulary, so its owner (typically UIManager) must call handle_key directly while this widget is focused (see wants_raw_keyboard).

Limitation: built on pygame’s KEYDOWN.unicode, so it only supports ASCII-range input, not full IME/composed-character entry. That is enough for names, chat, and join codes, but not for every language.

Usage example:

name_input = TextInput(40, 40, 240, 32, initial_text=”Player”, max_length=16)

Parameters:
  • x (float)

  • y (float)

  • width (float)

  • height (float)

  • initial_text (str)

  • max_length (int | None)

  • font (Font | None)

  • on_submit (Callable[[str], None] | None)

  • theme (Theme | None)

handle_key(data)[source]
Parameters:

data (KeyboardData) – The keyboard event to react to. Only KEYDOWN events (data.pressed) cause a change.

Returns:

Whether the key was consumed.

Return type:

bool

render(surface)[source]
Parameters:

surface (Surface)

Return type:

None

on_mouse_click(position, data)[source]
Parameters:
Return type:

bool