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>
27 lines
1.1 KiB
Text
27 lines
1.1 KiB
Text
# scroll_held.ludic - a scroll box held at an offset: scroll-top="{px}" puts it there every frame
|
|
# (the wheel, the bar and the focus still move it, and say so with on-scroll and event.value, for
|
|
# the program to keep or not), and ui_scroll_set(id or key, px) moves it once
|
|
export function ui_scroll_set(ui_st: mut UiState, key: string, px: float) -> void {
|
|
push(ui_st.sc_want_keys, key)
|
|
push(ui_st.sc_want_px, px)
|
|
}
|
|
# how far a box is scrolled before this frame's input: what it was, what ui_scroll_set asked for,
|
|
# or what its scroll-top says
|
|
function sc_held(ui_st: mut UiState, n: UiNode, off: float, live: bool) -> float {
|
|
var at = off
|
|
if live {
|
|
let keys = new []string
|
|
let pxs = new []float
|
|
for i in 0 .. len(ui_st.sc_want_keys) {
|
|
if ui_st.sc_want_keys[i] == n.key or (n.id != "" and ui_st.sc_want_keys[i] == n.id) { at = ui_px(ui_st, ui_st.sc_want_px[i]) } else {
|
|
push(keys, ui_st.sc_want_keys[i])
|
|
push(pxs, ui_st.sc_want_px[i])
|
|
}
|
|
}
|
|
ui_st.sc_want_keys = keys
|
|
ui_st.sc_want_px = pxs
|
|
}
|
|
let v = ui_attr(n, "scroll-top")
|
|
if Value.kind(v) != 0 { at = ui_px(ui_st, el_num(vl_text(v))) }
|
|
return at
|
|
}
|