Tunal/crates/tunal/ui/motion.slint

109 lines
4.5 KiB
Text

// Motion tokens: Material 3 durations and easings. Wrap every duration in `Motion.time()`
// so reduced motion makes it instant.
// The flag Rust sets (portal enable-animations, or TUNAL_REDUCED_MOTION=1). Kept apart from
// Motion because easing properties can't be exported to Rust.
export global MotionPrefs {
in property <bool> reduced;
// Length of a list change (insert, remove, reorder), read by the folder model when it
// starts one; 0 under reduced motion, which makes the model skip the transition.
out property <duration> list-change: Motion.time(Motion.medium1);
}
export global Motion {
out property <bool> reduced: MotionPrefs.reduced;
// No time at all: a change that must not animate (rows swapping content).
out property <duration> none: 0ms;
// How long such a change is held before animation comes back.
out property <duration> snap-pause: 60ms;
out property <duration> short1: 50ms;
out property <duration> short2: 100ms;
out property <duration> short3: 150ms;
out property <duration> short4: 200ms;
out property <duration> medium1: 250ms;
out property <duration> medium2: 300ms;
out property <duration> medium3: 350ms;
out property <duration> medium4: 400ms;
out property <duration> long1: 450ms;
out property <duration> long2: 500ms;
out property <duration> long3: 550ms;
out property <duration> long4: 600ms;
// Emphasized is a two-segment path in M3; this is its usual single-bezier stand-in.
out property <easing> emphasized: cubic-bezier(0.2, 0, 0, 1);
out property <easing> emphasized-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1);
out property <easing> emphasized-accelerate: cubic-bezier(0.3, 0, 0.8, 0.15);
out property <easing> standard: cubic-bezier(0.2, 0, 0, 1);
out property <easing> standard-decelerate: cubic-bezier(0, 0, 0, 1);
out property <easing> standard-accelerate: cubic-bezier(0.3, 0, 1, 1);
// Press squeeze (scale while held): small controls squeeze most, wide ones least.
out property <float> squeeze-small: 0.9;
out property <float> squeeze: 0.96;
out property <float> squeeze-large: 0.985;
// Scale a floating surface starts from (and leaves towards), never 0.
out property <float> enter-scale: 0.92;
// How long a toast without progress or action stays. A delay, not motion.
out property <duration> toast-timeout: 4s;
// One sweep of an indeterminate progress bar.
out property <duration> indeterminate-period: 1500ms;
// Time a wavy progress line takes to travel one wavelength.
out property <duration> wave-period: 1000ms;
// Hover time before a tooltip shows. A delay, not motion: reduced motion keeps it.
out property <duration> tooltip-delay: 500ms;
// How long a drag hovers over a tab before the tab opens (not shortened by reduced motion).
out property <duration> drag-switch-delay: 700ms;
// How far content slides when a folder opens in a direction of travel.
out property <length> travel-shift: 32px;
// How far content rises as it fades in when a folder opens.
out property <length> rise-shift: 12px;
public pure function time(d: duration) -> duration {
reduced ? 0ms : d
}
// Position of a clock-driven transition (`MotionClock`) at progress t in 0..1: a cubic
// ease-out, the stand-in for emphasized-decelerate where Slint can't apply an easing.
// The folder model (Rust) uses the same curve when a transition is interrupted.
public pure function settle(t: float) -> float {
1 - pow(1 - clamp(t, 0, 1), 3)
}
}
// A transition clock: `progress` runs from 0 to 1 over `duration` after each change of
// `epoch`, and is 1 otherwise. It ticks only while running, so nothing repaints when idle.
// Use it where a value must jump to a start point and then settle (rows that change place),
// which a property `animate` can't express.
export component MotionClock {
in property <int> epoch;
in property <duration> duration;
out property <bool> running;
out property <float> progress: root.running ? (animation-tick() - root.start) / root.duration : 1;
callback settled;
property <duration> start;
changed epoch => {
if root.duration > 0ms {
root.start = animation-tick();
root.running = true;
// A change while running starts over from here.
timer.restart();
}
}
timer := Timer {
running: root.running;
interval: root.duration;
triggered => {
root.running = false;
root.settled();
}
}
}