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>
83 lines
3.2 KiB
Text
83 lines
3.2 KiB
Text
# ui_inputs.ludic — more of ludic.ui's controls, driven by the keys: a number field takes typed digits
|
|
# (Enter or leaving it commits them, held between min and max) and steps with the arrows; a key field
|
|
# listens for the next key (Tab included), Esc stops it listening and Backspace unbinds it; a range
|
|
# shows its value as a percentage or with decimals and a unit; a label carries a note; an action may
|
|
# call an event named set; and a string prop given a number reads it as text.
|
|
import "ludic.ui"
|
|
import "ui_inputs_parts/Form.ludic"
|
|
import "ui_inputs_parts/Tag.ludic"
|
|
program UiInputs {
|
|
numbers float
|
|
function frame(ui_st: mut UiState, i: UiInput) -> UiNode {
|
|
ui_input(ui_st, i)
|
|
ui_show(ui_st, "Form", null, 0.0, 0.0, 400.0, 400.0)
|
|
let root: UiNode = ui_nodes(ui_st, "Form", null)
|
|
ui_place(ui_st, root, 0.0, 0.0, 400.0, 400.0)
|
|
return root.children[0]
|
|
}
|
|
function keys(tab: bool, shift: bool, enter: bool, left: bool) -> UiInput {
|
|
let i = new UiInput
|
|
i.tab = tab
|
|
i.shift = shift
|
|
i.enter = enter
|
|
i.left = left
|
|
if tab { i.key = Key.Tab }
|
|
if enter { i.key = Key.Enter }
|
|
return i
|
|
}
|
|
function typed(s: string) -> UiInput {
|
|
let i = new UiInput
|
|
i.typed = s
|
|
return i
|
|
}
|
|
function shown_state(page: UiNode) -> string { return page.children[len(page.children) - 1].text }
|
|
function last(n: UiNode) -> string { return n.children[len(n.children) - 1].text }
|
|
entry (ui_st: mut UiState) {
|
|
ui_backend(ui_st, new UiBackend)
|
|
var page = frame(ui_st, new UiInput)
|
|
frame(ui_st, keys(true, false, false, false))
|
|
frame(ui_st, typed("12"))
|
|
page = frame(ui_st, keys(false, false, true, false))
|
|
let shown = page.children[0].children[1].children[0].text
|
|
let a = shown_state(page)
|
|
frame(ui_st, typed("99"))
|
|
page = frame(ui_st, keys(true, false, false, false))
|
|
let b = shown_state(page)
|
|
frame(ui_st, keys(true, true, false, false))
|
|
page = frame(ui_st, keys(false, false, false, true))
|
|
let c = shown_state(page)
|
|
let note = page.children[0].children[0].children[1].text
|
|
frame(ui_st, keys(true, false, false, false))
|
|
let space = page.children[1].children[1].children[0].text
|
|
frame(ui_st, keys(false, false, true, false))
|
|
let cap = ui_capturing(ui_st)
|
|
page = frame(ui_st, keys(true, false, false, false))
|
|
let d = shown_state(page)
|
|
frame(ui_st, keys(false, false, true, false))
|
|
let esc = new UiInput
|
|
esc.escape = true
|
|
esc.key = Key.Escape
|
|
page = frame(ui_st, esc)
|
|
let e = shown_state(page)
|
|
let back = new UiInput
|
|
back.backspace = true
|
|
page = frame(ui_st, back)
|
|
let f = shown_state(page)
|
|
frame(ui_st, keys(true, false, false, false))
|
|
let right = new UiInput
|
|
right.right = true
|
|
page = frame(ui_st, right)
|
|
page = frame(ui_st, new UiInput)
|
|
let button = page.children[4]
|
|
let click = new UiInput
|
|
click.x = button.x + 2.0
|
|
click.y = button.y + 2.0
|
|
click.down = true
|
|
frame(ui_st, click)
|
|
let up = new UiInput
|
|
up.x = click.x
|
|
up.y = click.y
|
|
page = frame(ui_st, up)
|
|
print(`count {shown} {a} | {b} | {c} | {note} | {space} listening {cap} {d} | {e} | {f} | {last(page.children[2])} {last(page.children[3])} | {shown_state(page)} | {page.children[5].text}`)
|
|
}
|
|
}
|