Skip to main content

MenuProvider

Trait MenuProvider 

Source
pub trait MenuProvider {
    type MenuId: Copy + Debug + PartialEq;

    // Required methods
    fn title(&self, menu: Self::MenuId) -> &str;
    fn options(&self, menu: Self::MenuId) -> &[MenuOption];
    fn option_count(&self, menu: Self::MenuId) -> u8;
    fn scrollable(&self, menu: Self::MenuId) -> bool;
    fn layout(&self, menu: Self::MenuId) -> MenuLayout;
}
Expand description

Provider of static menu definitions (titles, options, layouts).

MenuProvider decouples menu data from menu state and rendering. The implementing crate supplies concrete menu IDs and the associated data; the engine’s MenuSystem consumes this data without knowing anything about the game’s menu hierarchy.

§Associated Types

  • MenuId — an enum (or other Copy + PartialEq + Debug type) that identifies which menu screen to display.

Required Associated Types§

Source

type MenuId: Copy + Debug + PartialEq

The type that identifies a specific menu screen.

Required Methods§

Source

fn title(&self, menu: Self::MenuId) -> &str

Title string displayed at the top of the menu box.

Source

fn options(&self, menu: Self::MenuId) -> &[MenuOption]

The list of options for this menu. The returned slice must live at least as long as self.

Source

fn option_count(&self, menu: Self::MenuId) -> u8

Number of visible options (for cursor bounds checking and scroll window size).

Source

fn scrollable(&self, menu: Self::MenuId) -> bool

Whether the option list can scroll when it exceeds the visible window.

Source

fn layout(&self, menu: Self::MenuId) -> MenuLayout

Static layout descriptor (position, size, spacing, cursor policy).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§