Skip to main content

Function: createTooltip()

createTooltip(world, source, options): Tooltip

Defined in: ui/utilities/create-tooltip.ts:106

Attaches a tooltip to source - an already-interactable entity (it must already carry a UiInteractableEcsComponent, e.g. from createButton or addUiInteractableComponent) - and a TooltipEcsComponent driving it.

The tooltip panel is parented directly to source with an anchor pinned to its top edge, pivoted at the panel's own bottom edge, so it floats just above source and follows it automatically as an ordinary UI child

  • createUiTooltipEcsSystem only ever toggles it visible/hidden, never repositions it. Both the panel and its label start hidden (enabled: false); createUiTooltipEcsSystem shows them once source has been continuously hovered or focused for showDelayMilliseconds.

A tooltip's draw order still follows hierarchy position like any other UI element (see the UI doc's "Draw order" note) - for a tooltip that must always render above every other element regardless of where its source sits in the tree, create it last, after every other UI element on the canvas.

Parameters​

world​

EcsWorld

The ECS world source belongs to.

source​

number

The interactable entity the tooltip appears near. Must already have a UiInteractableEcsComponent.

options​

CreateTooltipOptions

Options for configuring the tooltip. text, fontAtlas, textSize, and sprite have no sensible default and must always be provided.

Returns​

Tooltip

The created tooltip's panel and label entities.

Throws​

An error if source has no UiInteractableEcsComponent.