31 lines
1.2 KiB
Text
31 lines
1.2 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 = ui_st.sc_want_keys # the asks for this box taken out in place, the others kept
|
|
let pxs = ui_st.sc_want_px
|
|
var kept = 0
|
|
for i in 0 .. len(keys) {
|
|
if keys[i] == n.key or (n.id != "" and keys[i] == n.id) { at = ui_px(ui_st, pxs[i]) } else {
|
|
keys[kept] = keys[i]
|
|
pxs[kept] = pxs[i]
|
|
kept += 1
|
|
}
|
|
}
|
|
while len(keys) > kept {
|
|
List.pop(keys)
|
|
List.pop(pxs)
|
|
}
|
|
}
|
|
let v = ui_attr(n, "scroll-top")
|
|
if Value.kind(v) != 0 { at = ui_px(ui_st, el_numv(ui_st, v)) }
|
|
return at
|
|
}
|