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
| Composable | What it does |
|---|---|
useDensity | Follows the active density profile ("default", "touch" or "tv") |
useMetric | Returns a control height in pixels for the current density |
useResponsive | Picks a value by device, input mode, breakpoint or orientation |
useBackHandler | Handles back inputs (B on gamepad, Backspace on keyboard) while active |
useFocusScope | Keeps keyboard and gamepad focus inside a frame while active |
useFocusZone | A group of HUD controls skipped by focus until the player steps in; B steps out |
useHoldArrows | Holds gamepad selection on a control while it handles arrow keys itself |
useSize | Tracks an object's size in layout units, for layouts that react to available space |
useFit | Scales something down to the width its parent has, so words and rows never run out of a card |
useHasVisibleChild | Whether any child of a frame has Visible on, so a slot whose contents all hide can drop out of its layout |
useUiSound | Runs callbacks when components activate, toggle, open, close or select |
useTable | Manages sorted rows from raw tables and column definitions |
useSort | Sorts a list by one or more columns with tiebreakers |
useWhile | Runs a setup callback while a condition holds, cleaning up when it turns false |
useCountdown | Synchronised countdown of whole seconds remaining until a timestamp |
useDrag | Follows mouse or touch drags starting from a control |
useReveal | Types text out character by character for dialogue and notices |
useCount | Animates a number smoothly toward a target value |
useRequest | Calls the server, keeps the answer and requests again when inputs change |
useIntersect | Whether something has been scrolled near yet, for building it only then |
useDelayGroup | Shares an open delay and warm skip window across tooltips |
useDismiss | Closes floating content on Back or on a press outside it |
useFocus | Tracks whether keyboard or gamepad focus is on a control or inside it |
useHover | Tracks pointer hover over a target with open and close delays |
usePress | Tracks hold, long-press or toggle presses on a control |
useProximity | Tracks whether the local character is within a stud distance of a world target |
Lifetime and ownership
Call composables inside an active reactive owner:
- In a component: Inside
render(h), composables attach to that handle and stop whenhandle:destroy()runs. - In a scene: Inside
build(scene), composables attach to the scene and stop when the scene tears down. - 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()