mwg API
    Preparing search index...

    Class TextPrompt

    A modal single-line text field: a name entry, a save-slot label, a seed.

    Typing arrives through core.Input's onText, which is the signal a free text field listens to, so this plays no part in key bindings for characters: whatever the platform turns a key press into lands in the field. Editing and movement arrive as actions instead, which a game binds the way it binds everything else: left/right move the caret, backspace/delete edit, confirm accepts subject to validate, cancel gives up. The prompt is modal and swallows each of those while open, so the game underneath never walks away mid-name.

    onText wakes the most recently added listener first, so when two prompts overlap the topmost one gets the keystrokes - the same order the window stack shows them in.

    An in-progress IME composition previews below the field and only becomes value on commit, so CJK, dead keys and emoji pickers type through the same path the DOM gives every other input rather than through a game-specific workaround.

    import { TextPrompt } from '@datamoc/mwg/two-d/ui';

    const prompt = new TextPrompt({
    width: 320,
    height: 140,
    title: 'New hero',
    message: 'Name your hero (Enter keeps it)',
    maxLength: 12,
    validate: (value) => (value.trim() === '' ? 'Give them a name first.' : null),
    onConfirm: (value) => console.log('named', value),
    });

    Hierarchy (View Summary)

    Index
    anchor: "top" | "center" | "bottom"
    closable: boolean
    content: Container<ContainerChild> = ...
    delegate: { handleAction(action: string): boolean } | null = null

    A widget offered actions before the window itself sees them.

    Set it to the list or field the window exists to show. Without it, every window holding a widget has to override handleAction just to forward, which is noise at best and, done by assigning over the method, a trap.

    dims: boolean
    modal: boolean
    onClose: Signal<void> = ...
    • get closed(): boolean

      true once close() (or destroy()) has run. A closed window is spent: close() freed it and its contents through Pixi, so the caller's this.someWindow reference must not be written to any more. Guard with this rather than discovering it as a null-internal throw, and drop the reference.

      Returns boolean

    • get contentWidth(): number

      the space available inside the frame, which is what contents should lay out against

      Returns number

    • get error(): string | null

      the last validation error, or null when the value currently passes

      Returns string | null

    • Announces the close and frees this window and its contents. Idempotent, so a second close() (a pop() racing a cancel, a closeAll() after a manual close) is a no-op rather than a second destroy. The instance is spent afterwards; see closed.

      With animation it plays the opening backwards first and closes when it ends (driven by update(dt)), unless reduced motion is on, when it closes at once.

      Parameters

      Returns void

    • 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 });
    • Offered every action while this window is on top of the stack.

      Parameters

      • action: string

      Returns boolean

      true if the window used it, which stops it going any further down

    • Offered a click that landed on the blocker, at x, y in this window's own coordinates (its top-left corner is 0, 0). A click outside the window closes it when it is closable - the pointer's answer to handleAction('cancel') - and a click on the window itself is swallowed without closing, so its frame and empty body are never a dismiss button.

      The blocker calls this for every click it takes, which is all a game usually needs; it is public because it is also the whole decision, and a headless test can ask it directly.

      Parameters

      • x: number
      • y: number

      Returns boolean

      true when the click closed the window

    • Plays the opening animation from the window's current position. The stack calls update(dt) on its top window, which drives it. Under reduced motion the window simply appears.

      Parameters

      Returns void

      import { Window } from '@datamoc/mwg/two-d/ui';

      const window = new Window({ width: 240, height: 120, title: 'Result' });
      window.open({ animation: 'pop' });
      window.update(0.25); // normally the WindowStack's update does this
      console.log(window.scale.x); // 1
    • positions the window in a viewport of the given size, per its anchor

      Parameters

      • viewportWidth: number
      • viewportHeight: number

      Returns void