gale.ui.list_view module

This file contains the implementation of the class ListView: a vertical list of selectable (label, on_select) items, navigable by mouse or keyboard/gamepad.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.ui.list_view.ListView(x, y, width, height, items, font=None, cursor=None, theme=None)[source]

Bases: Widget

A vertical list of selectable items, each a (label, on_select) pair. Supports both keyboard navigation (on_navigate moves the selection with wraparound, on_confirm invokes the selected item) and mouse interaction (hovering highlights, clicking selects and invokes). This is the generalization of gale.ui’s “menu”: build a menu as Container([Panel(…), ListView(…)]).

Usage example:

menu = ListView(

40, 40, 240, 120, items=[(“Host”, start_hosting), (“Join”, start_joining), (“Quit”, quit_game)],

)

Parameters:
  • x (float)

  • y (float)

  • width (float)

  • height (float)

  • items (Sequence[Tuple[str, Callable[[], None]]])

  • font (Font | None)

  • cursor (Cursor | None)

  • theme (Theme | None)

row_height()[source]
Return type:

float

row_rect(index)[source]
Parameters:

index (int)

Return type:

Rect

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