gale.ui.manager module

This file contains the implementation of the class UIManager: connects a widget tree (a root Container) to gale.input_handler, rescaling mouse positions and routing keyboard/confirm/navigation input to the right widget.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.ui.manager.UIManager(root, virtual_width, window_width, virtual_height, window_height, confirm_action='confirm', navigate_actions=None)[source]

Bases: object

Connects a widget tree (a root Container) to gale.input_handler, rescaling mouse positions from window to virtual coordinates and routing keyboard “confirm”/navigation actions and raw key events to the right widget.

Not self-registered with InputHandler.register_listener: like StateMachine/StateStack, its owner (typically a BaseState) must call on_input manually, so only the currently active UI receives input.

Usage example:

class LobbyState(BaseState):
def enter(self, **kwargs) -> None:
self.ui = UIManager(

build_lobby_menu(), virtual_width=settings.VIRTUAL_WIDTH, window_width=settings.WINDOW_WIDTH, virtual_height=settings.VIRTUAL_HEIGHT, window_height=settings.WINDOW_HEIGHT, confirm_action=”confirm”, navigate_actions={“move_up”: (0, -1), “move_down”: (0, 1)},

)

def update(self, dt: float) -> None:

self.ui.update(dt)

def render(self, surface: pygame.Surface) -> None:

self.ui.render(surface)

def on_input(self, input_id: str, input_data) -> None:

self.ui.on_input(input_id, input_data)

Parameters:
  • root (Container)

  • virtual_width (int)

  • window_width (int)

  • virtual_height (int)

  • window_height (int)

  • confirm_action (str)

  • navigate_actions (Dict[str, Tuple[int, int]] | None)

update(dt)[source]
Parameters:

dt (float)

Return type:

None

render(surface)[source]
Return type:

None

on_input(input_id, input_data)[source]
Parameters:
  • input_id (str) – The action id notified by InputHandler.

  • input_data – The associated input data.

Return type:

None