# ui_scrollbar.ludic — a scroll box's bar held and dragged: a press on the thumb holds it where it # was taken, the pointer held moves it in proportion, letting go leaves it; a press on the track # jumps the thumb's middle there; the wheel still scrolls; and the rows under the bar are never pressed. import "ludic.ui" import "ui_scrollbar_parts/Long.ludic" program UiScrollbar { numbers float state UiScrollbarState { bx: float = 0.0 by: float = 0.0 } function frame(ui_st: mut UiState, i: UiInput) -> UiNode { ui_input(ui_st, i) ui_show(ui_st, "Long", null, 0.0, 0.0, 400.0, 400.0) let root: UiNode = ui_nodes(ui_st, "Long", null) ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0) return root.children[0] } # the pointer at (bx + x, by + y), held or not; how far the box is scrolled then function at(ui_scrollbar_st: UiScrollbarState, ui_st: mut UiState, x: float, y: float, down: bool) -> int { let i = new UiInput i.x = ui_scrollbar_st.bx + x i.y = ui_scrollbar_st.by + y i.down = down return int(frame(ui_st, i).children[0].scroll_y) } function wheel(ui_scrollbar_st: UiScrollbarState, ui_st: mut UiState, x: float, y: float) -> int { let i = new UiInput i.x = ui_scrollbar_st.bx + x i.y = ui_scrollbar_st.by + y i.wheel = 1.0 frame(ui_st, i) return int(frame(ui_st, new UiInput).children[0].scroll_y) } entry (ui_scrollbar_st: mut UiScrollbarState, ui_st: mut UiState) { ui_backend(ui_st, new UiBackend) let list = frame(ui_st, new UiInput).children[0] ui_scrollbar_st.bx = list.x ui_scrollbar_st.by = list.y let grab = at(ui_scrollbar_st, ui_st, 195.0, 10.0, true) let moved = at(ui_scrollbar_st, ui_st, 195.0, 40.0, true) let far = at(ui_scrollbar_st, ui_st, 195.0, 300.0, true) let back = at(ui_scrollbar_st, ui_st, 195.0, 25.0, true) let kept = at(ui_scrollbar_st, ui_st, 195.0, 25.0, false) at(ui_scrollbar_st, ui_st, 0.0 - ui_scrollbar_st.bx - 1.0, 0.0 - ui_scrollbar_st.by - 1.0, false) let jump = at(ui_scrollbar_st, ui_st, 195.0, 80.0, true) at(ui_scrollbar_st, ui_st, 195.0, 80.0, false) let wheeled = wheel(ui_scrollbar_st, ui_st, 50.0, 50.0) at(ui_scrollbar_st, ui_st, 50.0, 20.0, true) at(ui_scrollbar_st, ui_st, 50.0, 20.0, false) let page = frame(ui_st, new UiInput) print(`grab {grab} moved {moved} far {far} back {back} kept {kept} | jump {jump} | wheel {wheeled} | {page.children[1].text}`) } }