ludic/packages/ludic.ui/transition.ludic
Orkuncakilkaya a4c7a756f0 feat(ui): a scrollbar held where it was taken, a popover that keeps the mouse, easing that lands
- the scrollbar is .ui-scrollbar with a .ui-thumb, styled by the default sheet or a theme; a press
  on the thumb holds it at the point it was taken and the pointer moves it in proportion, a press on
  the track jumps the thumb's middle there and holds it, and neither presses what is under the bar
  (it used to centre the thumb on the pointer and press the row beneath as well);
- while a popover is up only scroll boxes inside it take the pointer, and a press outside it that
  closes it forgets any press in progress;
- a transition ends exactly on its value (it stopped a rounding error short, at every frame rate).

Tests: ui_popover_mouse, ui_scrollbar, ui_ease (60/120/180/240 Hz).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 21:39:28 +03:00

32 lines
1 KiB
Text

# transition.ludic - `transition: opacity 0.2s`: when an element's opacity changes from one frame to
# the next it eases to the new value over that time instead of jumping (opacity is the property a
# game fades most; the others arrive as they are)
var tr_keys: []string = new []string
var tr_from: []float = new []float
var tr_to: []float = new []float
var tr_at: []float = new []float
function tr_apply(n: UiNode) -> void {
if n.tr_dur <= 0.0 { return }
let now = an_now()
let want = n.alpha
for i in 0 .. len(tr_keys) {
if tr_keys[i] == n.key {
if tr_to[i] != want {
tr_from[i] = tr_value(i, now, n.tr_dur)
tr_to[i] = want
tr_at[i] = now
}
n.alpha = tr_value(i, now, n.tr_dur)
return
}
}
push(tr_keys, n.key)
push(tr_from, want)
push(tr_to, want)
push(tr_at, now)
}
function tr_value(i: int, now: float, dur: float) -> float {
let t = Math.clamp((now - tr_at[i]) / dur, 0.0, 1.0)
if t >= 1.0 { return tr_to[i] }
return tr_from[i] + (tr_to[i] - tr_from[i]) * t
}