mini_arcade_core.ui.menu

Menu system for mini arcade core.

Classes

MenuItem

Represents a single item in a menu.

MenuStyle

Styling options for the Menu.

Menu

A simple text-based menu system.

MenuWorld

Data model for menu scenes.

MenuIntent

Represents the user's intent in the menu for the current tick.

MenuTickContext

Context for a single tick of the menu scene.

MenuInputSystem

Converts InputFrame -> MenuIntent.

MenuNavigationSystem

Menu navigation system.

MenuActionSystem

Menu action execution system.

MenuRenderSystem

Menu rendering system.

BaseMenuScene

Base scene class for menu-based scenes.

Module Contents

class mini_arcade_core.ui.menu.MenuItem

Represents a single item in a menu.

Variables:
  • (str) (label) – The text label of the menu item.

  • (BaseCommand) (on_select) – The action to perform when the item is selected.

id: str
label: str
command_factory: Callable[[], mini_arcade_core.engine.commands.Command]
label_fn: Callable[[object], str] | None = None
resolved_label(ctx: object) str

Get the resolved label for this menu item.

Parameters:

ctx (object) – The current ctx instance.

Returns:

The resolved label string.

Return type:

str

class mini_arcade_core.ui.menu.MenuStyle

Styling options for the Menu.

Variables:
  • (Color) (hint_color) – Color for unselected items.

  • (Color) – Color for the selected item.

  • (int) (item_font_size) – Vertical spacing between items.

  • (Color) – Color for the title text.

  • (int) – Vertical space between title and first item.

  • (int) – Additional margin below the title.

  • None) (hint (str |) – Solid background color for the menu.

  • None) – Full-screen overlay color.

  • None) – Color for the panel behind content.

  • (int) – Horizontal padding inside the panel.

  • (int) – Vertical padding inside the panel.

  • (bool) (button_enabled) – Whether to render items as buttons.

  • (Color) – Fill color for buttons.

  • (Color) – Border color for buttons.

  • (Color) – Border color for the selected button.

  • None) – Fixed width for buttons, or None for auto-fit.

  • (int) – Fixed height for buttons.

  • (int) – Vertical gap between buttons.

  • (int) – Horizontal padding inside buttons.

  • None) – Optional hint text to display at the bottom.

  • (Color) – Color for the hint text.

  • (int) – Additional margin below the hint text.

  • (int) – Font size for the title text.

  • (int) – Font size for the hint text.

  • (int) – Font size for the menu items.

normal: mini_arcade_core.backend.types.Color = (220, 220, 220)
selected: mini_arcade_core.backend.types.Color = (255, 255, 0)
line_height: int = 28
title_color: mini_arcade_core.backend.types.Color = (255, 255, 255)
title_spacing: int = 18
title_margin_bottom: int = 20
background_color: mini_arcade_core.backend.types.Color | None = None
overlay_color: mini_arcade_core.backend.types.Color | None = None
panel_color: mini_arcade_core.backend.types.Color | None = None
panel_padding_x: int = 24
panel_padding_y: int = 18
button_enabled: bool = False
button_fill: mini_arcade_core.backend.types.Color = (30, 30, 30, 1.0)
button_border: mini_arcade_core.backend.types.Color = (120, 120, 120, 1.0)
button_selected_border: mini_arcade_core.backend.types.Color = (255, 255, 0, 1.0)
button_width: int | None = None
button_height: int = 40
button_gap: int = 20
button_padding_x: int = 20
hint: str | None = None
hint_color: mini_arcade_core.backend.types.Color = (200, 200, 200)
hint_margin_bottom: int = 50
title_font_size = 44
hint_font_size = 14
item_font_size = 24
class mini_arcade_core.ui.menu.Menu(items: Sequence[MenuItem], *, viewport: tuple[int, int] | None = None, title: str | None = None, style: MenuStyle | None = None, on_select: Callable[[MenuItem], None] | None = None)

A simple text-based menu system.

items
viewport = None
title = None
style
selected_index = 0
stable_width = True
set_items(items: Sequence[MenuItem])

Set the menu items. :param items: Sequence of new MenuItem instances. :type items: Sequence[MenuItem]

set_selected_index(index: int)

Set the selected index of the menu. :param index: New selected index. :type index: int

set_labels(labels: Sequence[str])

Set the labels of the menu items. :param labels: Sequence of new labels for the menu items. :type labels: Sequence[str]

move_up()

Move the selection up by one item, wrapping around if necessary.

move_down()

Move the selection down by one item, wrapping around if necessary.

select()

Select the currently highlighted item, invoking its action.

handle_event(event: mini_arcade_core.backend.events.Event, *, up_key: int, down_key: int, select_key: int) bool

Handle an input event to navigate the menu.

Parameters:
  • event (Event) – The input event to handle.

  • up_key – Key code for moving selection up.

type up_key: int

Parameters:
  • down_key (int) – Key code for moving selection down.

  • select_key (int) – Key code for selecting the current item.

draw(surface: mini_arcade_core.backend.Backend)

Draw the menu onto the given backend surface.

Parameters:

surface (Backend) – The backend surface to draw on.

set_viewport(viewport: tuple[int, int])

Set the viewport size for the menu.

Parameters:

viewport (tuple[int, int]) – New viewport size.

class mini_arcade_core.ui.menu.MenuWorld

Bases: mini_arcade_core.scenes.sim_scene.BaseWorld

Data model for menu scenes.

Variables:
  • (int) (selected) – Currently selected menu item index.

  • (float) (_cooldown_timer) – Cooldown time between menu moves.

  • (float) – Internal timer for move cooldown.

entities: list = []
selected: int = 0
move_cooldown: float = 0.12
step_timer(dt: float)

Step the internal cooldown timer.

Parameters:

dt (float) – Delta time since last update.

can_move() bool

Check if the menu can move selection (cooldown elapsed).

Returns:

True if movement is allowed, False otherwise.

Return type:

bool

consume_move()

Consume a move action and reset the cooldown timer.

class mini_arcade_core.ui.menu.MenuIntent

Bases: mini_arcade_core.scenes.sim_scene.BaseIntent

Represents the user’s intent in the menu for the current tick.

Variables:
  • (bool) (quit) – Whether the user intends to move up.

  • (bool) – Whether the user intends to move down.

  • (bool) – Whether the user intends to select the current item.

  • (bool) – Whether the user intends to quit the menu.

move_up: bool = False
move_down: bool = False
select: bool = False
quit: bool = False
class mini_arcade_core.ui.menu.MenuTickContext

Bases: mini_arcade_core.scenes.sim_scene.BaseTickContext[MenuWorld, MenuIntent]

Context for a single tick of the menu scene.

Variables:
  • (InputFrame) (input_frame) – The current input frame.

  • (float) (dt) – Delta time since last tick.

  • (Menu) (menu) – The Menu instance.

  • (MenuWorld) (model) – The MenuWorld instance.

  • (CommandQueue) (commands) – The command queue for pushing commands.

  • None) (packet (RenderPacket |) – The current menu intent.

  • None) – Factory for quit command.

  • None) – The resulting render packet.

menu: Menu | None = None
quit_cmd_factory: callable | None = None
class mini_arcade_core.ui.menu.MenuInputSystem

Bases: mini_arcade_core.scenes.systems.builtins.InputIntentSystem

Converts InputFrame -> MenuIntent.

name: str = 'menu_input'
build_intent(ctx: MenuTickContext)

Build the intent

class mini_arcade_core.ui.menu.MenuNavigationSystem

Menu navigation system.

name: str = 'menu_nav'
order: int = 20
step(ctx: MenuTickContext)

Update menu selection based on intent.

class mini_arcade_core.ui.menu.MenuActionSystem

Menu action execution system.

name: str = 'menu_actions'
order: int = 30
step(ctx: MenuTickContext)

Execute actions based on menu intent.

class mini_arcade_core.ui.menu.MenuRenderSystem

Bases: mini_arcade_core.scenes.systems.builtins.BaseQueuedRenderSystem[MenuTickContext]

Menu rendering system.

name: str = 'menu_render'
merge_existing_draw_ops: bool = False
emit(ctx: MenuTickContext, rq)

Emit draw calls into the render queue.

Parameters:
  • ctx (BaseTickContext) – The tick context containing world state and other info.

  • rq (RenderQueue) – The render queue to emit draw calls into.

class mini_arcade_core.ui.menu.BaseMenuScene(ctx: mini_arcade_core.runtime.context.RuntimeContext)

Bases: mini_arcade_core.scenes.sim_scene.SimScene[MenuTickContext, MenuWorld]

Base scene class for menu-based scenes.

Variables:

(MenuWorld) (world) – The data model for the menu scene.

menu: Menu
on_enter()

Called when the scene becomes active (safe place to create world & add systems).

property menu_title: str | None

Get the title of the menu.

Returns:

The menu title string, or None for no title.

Return type:

str | None

menu_style() MenuStyle

Get the style configuration for the menu.

Returns:

The MenuStyle instance for styling the menu.

Return type:

MenuStyle

abstractmethod menu_items() list[MenuItem]

Get the list of menu items for the menu.

Returns:

List of MenuItem instances for the menu.

Return type:

list[MenuItem]

quit_command()

Get the command to execute when quitting the menu.

Returns:

The command to execute on quit.

Return type:

Command

menu_viewport() tuple[int, int]

Get the viewport size for the menu.

Returns:

The viewport size tuple (width, height).

Return type:

tuple[int, int]