Skip to content

Input and motion

Declare native feedback and tracking so a widget can animate without rerendering Luau on each pointer sample. Add callbacks only for the state changes your interaction needs. See the island guide for expansion and outside dismissal.

ctx.format.measure(text, style) returns width and height in points using the same font and rounding as ui.text. The optional style accepts font, size, weight, maxWidth, lines and quarter. Style-local font families work here too. Text wraps only when lines > 1 and maxWidth > 0; a single line keeps its full width. Set quarter = true to swap width and height for text rotated by 90 degrees. Measurement runs inside the render budget.

local width, height = ctx.format.measure("12", { font = "Space Grotesk", size = 40, weight = "bold" })

Press feedback is native: add pressScale, pressOpacity, pressFill and pressAnimate to an element. It starts on mouse-down and restores on release or cancellation, without calling Luau. pressAnimate uses the same presets, duration or custom curve as animate. A transparent pressFill = 0 explicitly overrides the base fill. Add onPress(ctx, event) only when behavior needs the down, up and cancel boundaries.

onHover(ctx, event) receives began after hoverDelay seconds and ended after hoverGrace seconds. Leaving before dwell cancels entry; returning during grace cancels exit. Both delays default to zero and accept 0–60 seconds. Pointer movement does not call Luau.

function render(ctx)
return ui.box{
w = 240, h = if ctx.state.peek then 80 else 32,
fill = "#000000", radius = 16, animate = "spring",
hoverDelay = 0.16, hoverGrace = 0.12,
onHover = function(next, event) next.state.peek = event.phase == "began" end,
pressScale = 0.97, pressOpacity = 0.85, pressAnimate = "ease",
onClick = function(next) next.state.expanded = not next.state.expanded end,
ui.text{ text = "My island", color = "#ffffff" },
}
end

The five new handlers—onPress, onHover, onGesture, onKey and onOutsidePress—accept callback functions only. Existing onClick, onRightClick and onScroll retain their command-string form. Pointer events expose element-local x and y in points, with the origin at the top left; press events also include button and clicks.

Set cursor = "grab" on a grip or corner zone to show an open hand, or cursor = "pointer" on a button or tab to show a pointing hand. The topmost hit element with a cursor declaration wins. Elements without a cursor do not claim it; leaving the declared zones or the surface restores the arrow. Decorative subtrees, ui.glass and ui.shape do not accept cursor declarations. On a component, put cursor on the view’s returned visible root rather than the ui.component mount.

The surface changes the native cursor only when the resolved hover cursor changes. Manipulation begin/end integration selects a closed hand during a drag and restores the hovered cursor on release; it does not set the cursor on every pointer sample.

A gesture declaration opts into native pointer or trackpad recognition:

gesture = {
axis = "y", source = "both", threshold = 6,
lockDistance = 2, dominance = 1.3,
commit = { distance = 40, velocity = 300, direction = "up" },
},
onGesture = function(ctx, event)
if event.phase == "ended" and event.committed then ctx.state.expanded = false end
end,

Axes are x, y, free and auto (default); sources are pointer (default), scroll and both. Recognition defaults to a 4-point threshold, 1-point axis-lock distance and a 1.25 dominance ratio. The innermost element accepting the locked axis claims the gesture, cancels its click, and keeps capture outside its bounds until the gesture ends or is cancelled. Existing sliders and window-item dragging retain their native ownership.

Events use began, ended and cancelled. Set gestureEvents = "all" to also receive coalesced changed events; dx/dy are cumulative translation in points and vx/vy are velocity in points per second. By default, continuous changes stay native. committed is true at the end when an enabled distance or velocity threshold passes in the declared direction. Zero disables a criterion, and no enabled criteria means no commit. Directions are any (default), left, right, up and down.

onScroll preserves physical scroll phase and event.momentum (none, began, changed or ended). scrollMomentum = "consume" is the default; use "deliver" to receive momentum. Phase-less wheel events are delivered through onScroll; they do not synthesize an end using an idle timer. Gesture-driven visual tracking is separate from these logical gesture events.

Declared keyboard input and outside presses

Section titled “Declared keyboard input and outside presses”

An expanded island can use focusable = true, keys = {"left", "right", "escape"} and onKey(ctx, event). Declared keys are consumed synchronously by the focused native element; Luau receives key, optional characters, event["repeat"] and the existing modifier flags. Key names are lowercase; declarations normalize ASCII case and remove duplicates. There are at most 64 names, each 1–32 bytes. Standard names include escape, return, left, right, up, down, space and tab. Undeclared keys retain the existing native fallback. Set focusRing = false on a focusable presentation container to hide its native focus outline while keeping keyboard handling and focus ownership. Rings stay enabled by default; a child control that takes focus keeps its own ring.

onOutsidePress(ctx, event) works on elements in an island tree. Declare it on the visible capsule or expanded container rather than the fixed panel envelope. The handler receives the mouse button and local coordinates of an outside press; the original click continues to its destination. event.claimed is true when another element of the same island that accepts pointer input takes the press. Native monitoring exists only while a visible island needs outside handling or owns keyboard focus. Escape releases the island’s keyboard focus when declared.

Root widgets with trigger(ctx, event) receive {name = "reloaded", source = "host"} when a display instance is first created, and {name = "displayChanged", source = "host"} when its display identity or geometry changes. Visibility and focus remain data facts; they do not trigger this hook. The bundled profile preserves its presentation state while hidden. User-triggered events retain their existing name/value form without source. An island root without a popout also receives {name = "toggle", value = <display ID>} from shell toggle <root> and its keyboard shortcut, on the focused display. Component init, options and deinit remain package-level hooks.

Keep integrations in component service modules so replacing the island layout does not replace their data and actions.

Springs, element transitions and native dragging

Section titled “Springs, element transitions and native dragging”

Use animate = { response = 0.31, bounce = 0.22 } to choose a spring. response accepts 0.05–2.5 seconds; bounce accepts 0–0.95 and defaults to zero. Do not combine spring fields with duration or curve. The same form works for pressAnimate and element transitions. Interrupted scalar springs carry their velocity into the next target, bounded to a normalized magnitude of 20. Frame springs use independent position and size axes.

appear and exit describe an element’s insertion and removal relative to its normal paint. Opacity and scale multiply the painted values; dx and dy are point offsets. Omitted fields are identity values. Omitted transition animate uses the element’s motion, or a short fade when it has none; animate = "none" is instant. An exiting subtree keeps its last contents until native completion. Reintroducing its key under the same parent cancels the outgoing copy. These properties are separate from enter, which stages popout/drawer opening.

ui.box {
key = "activity", w = 220, h = 64,
animate = { response = 0.31, bounce = 0.22 },
appear = { opacity = 0, scale = 0.88 },
exit = { opacity = 0, scale = 0.88, animate = { response = 0.24, bounce = 0 } },
gesture = {
axis = "y", source = "both",
commit = { distance = 50, velocity = 300, direction = "up" },
track = {
dy = { 0, -40, rubber = 0.4 },
scale = { 1, 0.94 },
opacity = { 1, 0.8 },
},
},
onGesture = function(ctx, event)
if event.phase == "ended" and event.committed then
ctx.state.expanded = false
end
end,
}

Tracking needs a positive commit.distance, which defines full progress. track supports dx, dy, scale and opacity; each range has two endpoints and optional rubber from zero to one. Rubber affects overshoot beyond the endpoints. The native renderer applies these offsets without rendering Luau on each pointer sample. onGesture is optional: without it, release settles immediately. With it, committed release holds until that handler finishes, then settles alongside its new layout or returns to rest if the handler makes no visual change, fails, or is rejected. There is no timeout-based success path.

Apply tracking and appear/exit to a visible container around a mask; they are rejected directly on mask = true nodes. Reduce Motion keeps direct finger tracking and makes settlement instant. Animation speed applies to spring response and duration curves.

The editable lake profile keeps transition recipes in lib/lake/motion.luau. Its optional lib/lake/digits.luau prototype builds rolling numbers from ordinary clipped digit strips; it does not require a native text-animation API. Keep the default crossfade or replace that library to choose your own rollover behavior.

animate accepts a motion preset, curve name, duration in seconds, duration/curve table, or spring table. hoverAnimate accepts a motion preset or duration. loop repeats native paint motion as {from, to, seconds} for each of dx, dy, and rotate, with an optional paused; it does not schedule Luau renders. trail = true makes a moving indicator’s trailing edge settle 1.5 times slower.

enter is for popout/drawer opening; appear/exit are for keyed element insertion/removal. enter.from/to are fractions of opening progress. stretch adds native squash along a slide; d can start a path morph, whose endpoints need compatible commands. See effects and shader timing for custom curves and masks.

Set manipulationFollow = { response = 0.363, bounce = 0.42 } on the stable keyed target, next to manipulationCommit, rather than on its handle. Response accepts 0.05–2.5 seconds and bounce accepts 0–0.95, defaulting to zero. A widget tree accepts up to 24 follow targets, and each one moves and settles on its own. See detachable widgets for the move, resize and scale declarations and placement receipts.

manipulationFollow, reveal and morph are rejected on a ui.component mount. Declare them on the component view’s returned visible root instead; the mount does not forward these properties.

appear and exit gain anchor = { x = 1, y = 0.5 }, the scale pivot in normalized element coordinates. Both components are required when an anchor is supplied, and each accepts 0–1; omission uses the centre { x = 0.5, y = 0.5 }. delay accepts 0–2 seconds and defaults to zero. The planned presence behavior holds the transition’s starting appearance during the delay; animation speed scales both the delay and the transition.

appear = {
opacity = 0, scale = 0.05, anchor = { x = 1, y = 0.5 },
delay = 0.2, animate = { response = 0.36, bounce = 0 },
},

Declare reveal = { response = 0.36, bounce = 0.42 } on a ui.stack to provide opening/closing progress to its descendants. It uses the same response and bounce bounds as follow. reveal has no delay field. On a descendant ordinary element, including ui.glass, morph maps that progress through stops:

ui.stack {
key = "panel", reveal = { response = 0.36, bounce = 0.42 },
ui.column {
key = "contents",
morph = {
anchor = { x = 1, y = 0.5 },
stops = {
{ at = 0, scale = 0.05, opacity = 0 },
{ at = 0.25, scale = 0.4, opacity = 1 },
{ at = 1, scale = 1, opacity = 1 },
},
},
ui.text { text = "Panel contents" },
},
}

Use 2–16 stops with strictly increasing at values in −0.5–1.5, allowing an authored overshoot range. Element and group stops accept at, scale, opacity, dx and dy; omitted scale and opacity are 1, and offsets default to zero. A morph anchor has the same bounds and centre default as a presence anchor. A morph requires a reveal ancestor and cannot share its element with appear or exit. Glass-shape tracks use a separate set of stop fields and optional additive stretch.

A native editor without a manipulation owner is alpha-hidden while its reveal group is invisible, keeping its text, selection and first responder. It resumes sampled native layout when the group becomes visible. Editors owned by a manipulation target retain the full motion suppression and text-raster path.

Removing a reveal stack retains its subtree until the qualifying exits complete: the root’s own exit and each descendant exit with no exiting element between it and the root. An exiting section therefore owns its rows’ departure rather than also running every row exit. Removal outside a reveal root keeps the existing root-only behavior.

A decorative, unmasked ui.path can instead declare morph = { track = "shape-key" }. The key must name a unique rectangular ui.shape with a morph or reveal on the same surface. Author the path at the shape’s final geometry. Its path points then follow that shape’s sampled position, size, radius and rotation, using a rounded-box cage that preserves the authored path at rest. The native path and shape share one animation clock; no script callback runs per frame. Keep their ancestor transforms static or shared: independently moving wrappers still transform their own children. Track morphs take no stops or other morph fields. Reduce Motion places both directly at the final geometry.

pulse = { key = "arrival-1", duration = 0.4, rotate = { 0, -12, 0 } } plays once when its key changes on an ordinary element or whole glass body. The stable key is a string or integer; duration is greater than zero and at most 30 seconds. Supply at least one of rotate, scale, dx, dy, each a dense list of 2–256 finite samples in −1,000,000–1,000,000. Samples are evenly spaced over the duration. Every channel must end at zero so the element returns to its model value without a jump. Consecutive rotation samples must differ by less than 180 degrees; subdivide larger turns. The encoded recipe is capped at 16 KiB.

Rotation samples are degrees about the element centre. Scale samples are additive fractional offsets about the same centre (0 keeps the model scale, 0.1 enlarges it by 10%). Translation samples are point offsets in the parent coordinate space. Pulses compose with the element’s model scale and rotation. Re-rendering with the same key does not restart it; changing the key replaces the previous pulse. Removing the element or pulse cancels playback, including on a retained exit layer. Reduce Motion consumes the key without playback; a later key change can play when animations are enabled. Glass shapes reject pulse; use their shape morph and impulse contract instead.

shadowOffset = { x = 0, y = 7 } is now accepted on every element. Both components are required and bounded to −256–256 points. It sets the native layer shadow offset on ordinary elements, including text, and the glass recipe’s offset on native glass. gesture.track.outline = false or a Color is accepted only with move, resize or scale mode. It replaces the translucent white outline drawn around a resize preview: false draws none, and a Color draws that color.

Pulse

export type Pulse = {
key: string | number, duration: number, rotate: { number }?, scale: { number }?, dx: { number }?, dy: { number }?,
}

Fields: key, duration, rotate, scale, dx, dy

Motion

export type Motion = "none" | "spring" | "bouncy" | "smooth" | "ease"

Curve

export type Curve = "linear" | "easeIn" | "easeOut" | "easeInOut" | "back"
| "standard" | "standardAccel" | "standardDecel" | "emphasized" | "emphasizedAccel" | "emphasizedDecel"
| "fastSpatial" | "spatial" | "slowSpatial" | "fastEffects" | "effects" | "slowEffects" | { number }

Animate

export type Animate = Motion | Curve | number | { duration: number?, curve: Curve? } | { response: number, bounce: number? }

Fields: duration, curve, response, bounce

Presence

export type Presence = {
opacity: number?, scale: number?, dx: number?, dy: number?, animate: Animate?,
anchor: { x: number, y: number }?, delay: number?,
}

Fields: opacity, scale, dx, dy, animate, anchor, delay

reveal = { response, bounce, delay, hold } plans an opening spring after delay seconds and a closing spring after hold seconds. Both waits default to zero and accept 0–2 seconds. The presented frame and input visibility share that plan. A group whose morph has zero opacity through progress 0.02 has no interactive content during that part of the plan. A keyed group reopened during its retained close continues from that close state immediately, without restarting the entry delay. Reduce Motion presents the final layout immediately. Spring is the response/bounce pair used by impulses and edge springs; those contracts do not take reveal timing fields.

Spring

export type Spring = { response: number, bounce: number? }

Fields: response, bounce

Reveal

export type Reveal = Spring & { delay: number?, hold: number? }

Fields: delay, hold

MorphStop

export type MorphStop = { at: number, scale: number?, opacity: number?, dx: number?, dy: number? }

Fields: at, scale, opacity, dx, dy

Morph

export type Morph = { anchor: { x: number, y: number }?, stops: { MorphStop } } | { track: string }

Fields: anchor, stops, track

Enter

export type Enter = {
opacity: number?,
scale: number?,
dx: number?,
dy: number?,
from: number?,
to: number?,
curve: Curve?,
stretch: number?,
d: string?,
}

Fields: opacity, scale, dx, dy, from, to, curve, stretch, d

Gesture

export type Gesture = {
track: {
dx: GestureRange?, dy: GestureRange?, scale: GestureRange?, opacity: GestureRange?,
mode: ("move" | "resize" | "scale")?, target: string?,
bounds: { x: number, y: number, w: number, h: number }?,
min: { w: number, h: number }?, max: { w: number, h: number }?,
edge: ("n" | "s" | "e" | "w" | "nw" | "ne" | "sw" | "se")?,
inset: { x: number, y: number }?,
outline: (false | Color)?,
}?,
axis: ("x" | "y" | "free" | "auto")?,
source: ("pointer" | "scroll" | "both")?,
threshold: number?,
lockDistance: number?,
dominance: number?,
commit: { distance: number?, velocity: number?, direction: ("any" | "left" | "right" | "up" | "down")? }?,
}

Fields: track, axis, source, threshold, lockDistance, dominance, commit

GestureRange

export type GestureRange = { number } & { rubber: number? }

Fields: rubber

Click accepts a command string or callback for existing click/right-click/scroll actions and slider changes. Press, hover, gesture, keyboard, outside-press, and native-text handlers require callback functions. Event coordinates are element-local points; slider value is normalized to 0–1. Read event["repeat"] using bracket syntax.

InputHandler

export type InputHandler = (ctx: Context, event: Event) -> ()

Click

export type Click = string | InputHandler

Event

export type Event = {
transaction: string?,
rect: { x: number, y: number, w: number, h: number }?,
reason: string?,
button: "left" | "right" | "middle" | "none",
shift: boolean,
option: boolean,
control: boolean,
command: boolean,
dx: number,
dy: number,
precise: boolean,
value: number?,
phase: ("began" | "changed" | "ended" | "down" | "up" | "cancel" | "cancelled" | "selected" | "applied")?,
x: number?,
y: number?,
clicks: number?,
vx: number?,
vy: number?,
committed: boolean?,
momentum: ("none" | "began" | "changed" | "ended")?,
key: string?,
characters: string?,
text: string?,
focused: boolean?,
claimed: boolean?,
["repeat"]: boolean?,
}

Fields: transaction, rect, reason, button, shift, option, control, command, dx, dy, precise, value, phase, x, y, clicks, vx, vy, committed, momentum, key, characters, text, focused, claimed, repeat