mwg API
    Preparing search index...

    Class ListView

    A scrolling list of rows, driven by the keyboard.

    This is the workhorse of an inventory-heavy game: bags, spell lists, shop stock, dialogue choices, save slots. It scrolls by keeping the highlight in view rather than by pixel offset, which is what makes it feel right with a keyboard: the list moves only when the selection would otherwise leave the window.

    Rows that are disabled are skipped when moving, so holding a direction never lands on something unusable.

    import { ListView } from '@datamoc/mw_games/two-d/ui';

    const menu = new ListView({
    width: 160,
    height: 96,
    items: [
    { text: 'Attack' },
    { text: 'Item' },
    { text: 'Flee', disabled: true },
    ],
    onSelect: (item, index) => console.log('chose', item.text, index),
    });

    menu.handleAction('down'); // highlights "Item"
    menu.handleAction('confirm'); // fires onSelect for the highlighted row

    Hierarchy

    • Container
      • ListView
    Index
    onHighlight: ((item: ListItem, index: number) => void) | null
    onSelect: ((item: ListItem, index: number) => void) | null
    • Removes all internal references and listeners as well as removes children from the display list. Do not use a Container after calling destroy.

      Parameters

      • Optionaloptions: DestroyOptions

        Options parameter. A boolean will act as if all options have been set to that value

      Returns void

      container.destroy();
      container.destroy(true);
      container.destroy({ children: true });
      container.destroy({ children: true, texture: true, textureSource: true });
    • Parameters

      • action: string

      Returns boolean

      true when the action was used

    • Moves the highlight by delta rows, skipping disabled ones.

      Wraps at both ends, which is what a short menu wants. Returns false when there is nothing selectable to move to, so a caller can beep rather than doing nothing.

      Parameters

      • delta: number

      Returns boolean

    • Selects and confirms row index in one step, the way a mouse or touch player expects from a menu row rather than a select-then-confirm keyboard sequence - the same pointer parity IconGrid.tapCell already gives its cells. A disabled row is a no-op, the same as an out-of-range one. This is what a row's own pointerdown handler calls, so a game driving the list programmatically (a test, a gamepad-to-pointer bridge) reaches the exact behaviour a real tap would.

      Parameters

      • index: number

      Returns void