mwg API
    Preparing search index...

    Class TooltipHost

    Drives one Tooltip from rectangles instead of from each widget's own pointer events, which is what makes it work in the two places hover cannot reach: on a touch screen (a press that rests for longPress seconds shows the text, and releasing hides it) and over a disabled Button, which has no pointer events to receive (the host tests the button's bounds itself, and a greyed-out button is exactly the one worth explaining).

    Feed it pointer positions with pointerMove, pointerDown and pointerUp (or attach a PointerTracker), and call update(dt) each frame. The later a target was added, the higher it counts when targets overlap.

    import { Button, TooltipHost } from '@datamoc/mwg/two-d/ui';

    const host = new TooltipHost({ longPress: 0.4 });
    host.tooltip.setViewport(800, 600);

    const test = new Button({ width: 80, height: 28, text: 'Test', disabled: true,
    tooltip: () => 'Build a road across the gap first' });
    host.addButton(test);

    host.pointerMove(10, 10); // over the disabled button: the text still shows after the hover delay

    Hierarchy

    • Container
      • TooltipHost
    Index
    tooltip: Tooltip
    • a button's own bounds and tooltip, whether or not the button is disabled

      Parameters

      Returns () => void

    • a finger or button went down: the tooltip shows once it has rested for longPress

      Parameters

      • x: number
      • y: number

      Returns void

    • a pointer with no button down moved: the usual hover

      Parameters

      • x: number
      • y: number

      Returns void

    • Parameters

      • dt: number

      Returns boolean

      true on the frame the tooltip appears, as Tooltip.update does