ludic/packages/ludic.ui/transition.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

28 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)
function tr_apply(ui_st: mut UiState, n: UiNode) -> void {
if n.tr_dur <= 0.0 { return }
let now = an_now(ui_st)
let want = n.alpha
for i in 0 .. len(ui_st.tr_keys) {
if ui_st.tr_keys[i] == n.key {
if ui_st.tr_to[i] != want {
ui_st.tr_from[i] = tr_value(ui_st, i, now, n.tr_dur)
ui_st.tr_to[i] = want
ui_st.tr_at[i] = now
}
n.alpha = tr_value(ui_st, i, now, n.tr_dur)
return
}
}
push(ui_st.tr_keys, n.key)
push(ui_st.tr_from, want)
push(ui_st.tr_to, want)
push(ui_st.tr_at, now)
}
function tr_value(ui_st: UiState, i: int, now: float, dur: float) -> float {
let t = Math.clamp((now - ui_st.tr_at[i]) / dur, 0.0, 1.0)
if t >= 1.0 { return ui_st.tr_to[i] }
return ui_st.tr_from[i] + (ui_st.tr_to[i] - ui_st.tr_from[i]) * t
}