pesde goatsoft / lucy

Composables

A composable is a function named useX that creates refs, computeds and effects for whatever is running now: a component's render, a scene's build, an effect, or scope:run on a Lucy.effectScope(). Anything it creates stops when that owner stops. Calling a composable without an active owner throws an error.

To write your own composables, see Share logic with composables.

Built in composables

ComposableWhat it does
useDensityFollows the active density profile ("default", "touch" or "tv")
useMetricReturns a control height in pixels for the current density
useResponsivePicks a value by device, input mode, breakpoint or orientation
useBackHandlerHandles back inputs (B on gamepad, Backspace on keyboard) while active
useFocusScopeKeeps keyboard and gamepad focus inside a frame while active
useFocusZoneA group of HUD controls skipped by focus until the player steps in; B steps out
useHoldArrowsHolds gamepad selection on a control while it handles arrow keys itself
useSizeTracks an object's size in layout units, for layouts that react to available space
useFitScales something down to the width its parent has, so words and rows never run out of a card
useHasVisibleChildWhether any child of a frame has Visible on, so a slot whose contents all hide can drop out of its layout
useUiSoundRuns callbacks when components activate, toggle, open, close or select
useTableManages sorted rows from raw tables and column definitions
useSortSorts a list by one or more columns with tiebreakers
useWhileRuns a setup callback while a condition holds, cleaning up when it turns false
useCountdownSynchronised countdown of whole seconds remaining until a timestamp
useDragFollows mouse or touch drags starting from a control
useRevealTypes text out character by character for dialogue and notices
useCountAnimates a number smoothly toward a target value
useRequestCalls the server, keeps the answer and requests again when inputs change
useIntersectWhether something has been scrolled near yet, for building it only then
useDelayGroupShares an open delay and warm skip window across tooltips
useDismissCloses floating content on Back or on a press outside it
useFocusTracks whether keyboard or gamepad focus is on a control or inside it
useHoverTracks pointer hover over a target with open and close delays
usePressTracks hold, long-press or toggle presses on a control
useProximityTracks whether the local character is within a stud distance of a world target

Lifetime and ownership

Call composables inside an active reactive owner:

  1. In a component: Inside render(h), composables attach to that handle and stop when handle:destroy() runs.
  2. In a scene: Inside build(scene), composables attach to the scene and stop when the scene tears down.
  3. In scripts or effects: Outside components and scenes, wrap calls in an effect scope:
local scope = Lucy.effectScope()
scope:run(function()
    Lucy.useWhile(isOpen, blockInput)
end)

-- Stop everything created inside the scope:
scope:stop()