ludic/examples/library/ui_controls.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

71 lines
2.6 KiB
Text

# ui_controls.ludic — ludic.ui's own controls, driven as a player would drive them: Tab and the
# arrows move the focus, Enter presses and flips, the arrows move a range and step a select, typing
# fills a text field and Backspace takes a letter back, a key field takes the next key, the pointer
# drags a range, and the wheel scrolls a box. Every change reaches the component as an event.
import "ludic.ui"
import "ui_controls_parts/Settings.ludic"
program UiControls {
numbers float
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
ui_input(ui_st, i)
ui_show(ui_st, "Settings", null, 0.0, 0.0, 400.0, 400.0)
let root: UiNode = ui_nodes(ui_st, "Settings", null)
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
return root
}
function press(tab: bool, down: bool, right: bool, enter: bool) -> UiInput {
let i = new UiInput
i.tab = tab
i.down_key = down
i.right = right
i.enter = enter
return i
}
function state(root: UiNode) -> string {
let page = root.children[0]
let last = page.children[len(page.children) - 1]
return last.text
}
entry (ui_st: mut UiState) {
ui_backend(ui_st, new UiBackend)
var root = frame(ui_st, new UiInput)
root = frame(ui_st, press(true, false, false, false))
root = frame(ui_st, press(false, false, false, true))
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, false, true))
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, true, false))
root = frame(ui_st, press(false, false, true, false))
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, true, false))
root = frame(ui_st, press(false, true, false, false))
let typed = new UiInput
typed.typed = "lovelace"
root = frame(ui_st, typed)
let back = new UiInput
back.backspace = true
root = frame(ui_st, back)
root = frame(ui_st, press(false, true, false, false))
root = frame(ui_st, press(false, false, false, true))
let k = new UiInput
k.key = 70
root = frame(ui_st, k)
print(state(root))
let range = root.children[0].children[2]
let track = range.children[1]
let at = new UiInput
at.x = track.x + track.cw * 0.8
at.y = track.y + 2.0
at.down = true
root = frame(ui_st, at)
root = frame(ui_st, new UiInput)
let list = root.children[0].children[6]
let w = new UiInput
w.x = list.x + 5.0
w.y = list.y + 5.0
w.wheel = -1.0
root = frame(ui_st, w)
root = frame(ui_st, new UiInput)
print(`{state(root)}; scrolled {int(root.children[0].children[6].scroll_y)}`)
}
}