gale.ui.widget module

This file contains the implementation of the class Widget, the base every gale.ui widget (Panel, Button, Container, …) derives from.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.ui.widget.Widget(x, y, width, height, theme=None, visible=True, enabled=True)[source]

Bases: object

Base class for anything gale.ui can render and route input to.

A subclass overrides update/render to draw itself, and whichever of on_mouse_motion/on_mouse_click/on_confirm/on_navigate it reacts to. on_mouse_click, on_confirm, and on_navigate return a bool meaning “did I consume this?”, so a Container knows whether to keep forwarding the same input to something else (a click behind a focused widget should not also reach whatever is under it).

Parameters:
  • x (float)

  • y (float)

  • width (float)

  • height (float)

  • theme (Theme | None)

  • visible (bool)

  • enabled (bool)

focusable: bool = False
x: float
y: float
width: float
height: float
visible: bool
enabled: bool
focused: bool
hovered: bool
parent: Widget | None
wants_raw_keyboard: bool
property theme: Theme
property rect: Rect
contains(position)[source]
Parameters:

position (Tuple[float, float]) – A point, in the same coordinate space as x/y.

Returns:

Whether position is inside this widget’s rect.

Return type:

bool

update(dt)[source]
Parameters:

dt (float)

Return type:

None

render(surface)[source]
Parameters:

surface (Surface)

Return type:

None

on_mouse_motion(position)[source]
Parameters:

position (Tuple[float, float])

Return type:

None

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

bool

on_confirm()[source]
Return type:

bool

on_navigate(direction)[source]
Parameters:

direction (Tuple[int, int])

Return type:

bool