wip(0.S3): packages and examples migrated in one run - ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:02:45 +03:00
parent d490d4f9f1
commit 3eda72e8c2
172 changed files with 3094 additions and 2966 deletions

View file

@ -3,8 +3,6 @@
# the field commits, held between min and max; Backspace takes a digit back (of the value, when it is
# the first key), and the left and right arrows step it. Each commit is one on-change with the
# number: an int when step and the value are whole.
var ct_num_key: string = ""
var ct_num_text: string = ""
function ct_num_bound(n: UiNode, key: string) -> bool { return Value.kind(ui_attr(n, key)) != 0 }
function ct_num_step_of(n: UiNode) -> float {
let s = Value.as_float(ui_attr(n, "step"))
@ -17,57 +15,57 @@ function ct_num_clamp(n: UiNode, v0: float) -> float {
if ct_num_bound(n, "min") { v = Math.max(v, Value.as_float(ui_attr(n, "min"))) }
return v
}
function ct_num_set(n: UiNode, v0: float) -> void {
function ct_num_set(ui_st: mut UiState, n: UiNode, v0: float) -> void {
let v = ct_num_clamp(n, v0)
let step = ct_num_step_of(n)
let was = ui_attr(n, "value")
if Value.kind(was) != 0 and Value.as_float(was) == v { return }
if step == float(int(step)) and v == float(int(v)) { ct_change(n, Value.int(int(v))) } else { ct_change(n, Value.float(v)) }
if step == float(int(step)) and v == float(int(v)) { ct_change(ui_st, n, Value.int(int(v))) } else { ct_change(ui_st, n, Value.float(v)) }
}
# Enter, or the focus leaving it: the draft becomes the value (a draft of nothing changes nothing)
function ct_num_commit(n: UiNode) -> void {
if ct_num_key != n.key { return }
let s = ct_num_text
ct_num_key = ""
function ct_num_commit(ui_st: mut UiState, n: UiNode) -> void {
if ui_st.ct_num_key != n.key { return }
let s = ui_st.ct_num_text
ui_st.ct_num_key = ""
if s == "" or s == "-" or s == "." or s == "-." { return }
ct_num_set(n, el_num(s))
ct_num_set(ui_st, n, el_num(s))
}
function ct_num_step(n: UiNode, d: int) -> void {
function ct_num_step(ui_st: mut UiState, n: UiNode, d: int) -> void {
var base = Value.as_float(ui_attr(n, "value"))
if ct_num_key == n.key and ct_num_text != "" and ct_num_text != "-" { base = el_num(ct_num_text) }
ct_num_key = ""
ct_num_set(n, base + ct_num_step_of(n) * float(d))
if ui_st.ct_num_key == n.key and ui_st.ct_num_text != "" and ui_st.ct_num_text != "-" { base = el_num(ui_st.ct_num_text) }
ui_st.ct_num_key = ""
ct_num_set(ui_st, n, base + ct_num_step_of(n) * float(d))
}
# what was typed this frame, the characters a number can hold; Backspace takes one back
function ct_num_typed(n: UiNode) -> void {
if fc_key != n.key or (in_now.typed == "" and not in_now.backspace) { return }
if ct_num_key != n.key {
ct_num_key = n.key
ct_num_text = ""
if in_now.typed == "" { ct_num_text = ui_attr_text(n, "value") }
function ct_num_typed(ui_st: mut UiState, n: UiNode) -> void {
if ui_st.fc_key != n.key or (ui_st.in_now.typed == "" and not ui_st.in_now.backspace) { return }
if ui_st.ct_num_key != n.key {
ui_st.ct_num_key = n.key
ui_st.ct_num_text = ""
if ui_st.in_now.typed == "" { ui_st.ct_num_text = ui_attr_text(n, "value") }
}
if in_now.backspace and len(ct_num_text) > 0 { ct_num_text = ct_num_text[0..len(ct_num_text) - 1] }
if ui_st.in_now.backspace and len(ui_st.ct_num_text) > 0 { ui_st.ct_num_text = ui_st.ct_num_text[0..len(ui_st.ct_num_text) - 1] }
let step = ct_num_step_of(n)
let lo = Value.as_float(ui_attr(n, "min"))
for i in 0 .. len(in_now.typed) {
let c = in_now.typed[i]
for i in 0 .. len(ui_st.in_now.typed) {
let c = ui_st.in_now.typed[i]
let digit = c >= 48 and c <= 57
let minus = c == 45 and ct_num_text == "" and (not ct_num_bound(n, "min") or lo < 0.0)
let point = c == 46 and step != float(int(step)) and not ui_has(ct_num_text, ".")
if (digit or minus or point) and len(ct_num_text) < 24 { ct_num_text = ct_num_text + in_now.typed[i..i + 1] }
let minus = c == 45 and ui_st.ct_num_text == "" and (not ct_num_bound(n, "min") or lo < 0.0)
let point = c == 46 and step != float(int(step)) and not ui_has(ui_st.ct_num_text, ".")
if (digit or minus or point) and len(ui_st.ct_num_text) < 24 { ui_st.ct_num_text = ui_st.ct_num_text + ui_st.in_now.typed[i..i + 1] }
}
}
# the focus has gone from the field being typed in: what was typed is kept
function ct_num_blur(root: UiNode) -> void {
if ct_num_key == "" or ct_num_key == fc_key { return }
let n = fr_node(root, ct_num_key)
function ct_num_blur(ui_st: mut UiState, root: UiNode) -> void {
if ui_st.ct_num_key == "" or ui_st.ct_num_key == ui_st.fc_key { return }
let n = fr_node(root, ui_st.ct_num_key)
if n == null {
ct_num_key = ""
ui_st.ct_num_key = ""
return
}
ct_num_commit(n)
ct_num_commit(ui_st, n)
}
function ct_num_shown(n: UiNode) -> string {
if ct_num_key == n.key { return ct_num_text }
function ct_num_shown(ui_st: UiState, n: UiNode) -> string {
if ui_st.ct_num_key == n.key { return ui_st.ct_num_text }
return ct_value_text(n)
}