mwg API
    Preparing search index...

    Class Tooltip

    The hover explanation every dense interface needs: what this item does, what this stat means, why this button is disabled.

    The delay is counted in update(dt) rather than a setTimeout, the same choice IconGrid already made for long-press and WindowStack for its own timing: a frame-driven counter is exactly as testable as it is correct, and it cannot fire after the scene that owned it has gone away. The panel itself is a non-modal Window, so a tooltip inherits the theme's frame, padding and live restyling rather than drawing a second kind of panel that would drift from every other one the moment a game sets theme.panel.

    Positioning is the other half: a tooltip near the right or bottom edge flips back inside the viewport instead of being cut off, which is why setViewport has to be called from the owning scene's own resize.

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

    const tooltip = new Tooltip({ delay: 0 });
    tooltip.setViewport(800, 600);

    tooltip.hover('Strength: raises attack', 120, 80);
    // called every frame from the scene's own update(dt); returns true once, the frame it appears
    console.log(tooltip.update(1 / 60)); // true - delay is 0, so it shows on the first frame

    tooltip.leave(); // the pointer moved off the stat row

    Hierarchy

    • Container
      • Tooltip
    Index
    • get panelPosition(): { x: number; y: number }

      where the panel actually sits, after edge clamping - the value a layout test reads

      Returns { x: number; y: number }

    • get text(): string | null

      the text currently shown, or waiting out its delay; null when nothing is hovered

      Returns string | null

    • The pointer is resting on something with text to explain, at x/y.

      Safe to call every frame with the same arguments: the delay keeps counting rather than restarting. Calling it with different text restarts the wait, so sweeping across a row of icons shows the one the pointer settles on rather than the first one it crossed.

      Parameters

      • text: string
      • x: number
      • y: number

      Returns void

    • How big the wrapped text is, which decides the panel's size.

      Its own method purely so it can be overridden: Pixi measures text through a canvas, so reading a Label's width needs a DOM and nothing here can size itself under node --test. A test subclasses this and returns a fixed size, which leaves the parts actually worth testing (the hover delay, the edge flip, the clamp) fully exercised - the same subclass seam StageScript's tests already use in place of stubbing Pixi.

      Returns { height: number; width: number }

    • call from the owning scene's resize, so edge clamping knows what it is clamping to

      Parameters

      • width: number
      • height: number

      Returns void

    • Parameters

      • dt: number

      Returns boolean

      true on the frame the tooltip becomes visible, for a game that wants to cue a sound