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>
43 lines
1.3 KiB
Text
43 lines
1.3 KiB
Text
# tpl_lines.ludic - which line of its file an element is on
|
|
# the text being read, and where its lines start, so an element can say which line it is on
|
|
function tp_lines(ui_st: mut UiState, src: string) -> void {
|
|
ui_st.tp_nl = new []int
|
|
for i in 0 .. len(src) {
|
|
if src[i] == 10 { push(ui_st.tp_nl, i) }
|
|
}
|
|
}
|
|
function tp_line(ui_st: UiState, at: int) -> int {
|
|
var lo = 0
|
|
var hi = len(ui_st.tp_nl)
|
|
while lo < hi {
|
|
let mid = (lo + hi) / 2
|
|
if ui_st.tp_nl[mid] < at { lo = mid + 1 } else { hi = mid }
|
|
}
|
|
return lo + 1
|
|
}
|
|
|
|
# text beside elements (<button><img/>Resume</button>): each run of it a text of its own, in order
|
|
function tp_mixed(x: Xml) -> bool {
|
|
if Xml.child_count(x) == 0 or x.tag == "style" { return false }
|
|
for i in 0 .. len(x.mixed) {
|
|
if x.mixed[i].tag == "#text" { return true }
|
|
}
|
|
return false
|
|
}
|
|
function tp_read_mixed(ui_st: mut UiState, t: UiTpl, x: Xml, file: string, err: []string) -> void {
|
|
for i in 0 .. len(x.mixed) {
|
|
let m = x.mixed[i]
|
|
if m.tag == "#text" {
|
|
let r = new UiTpl
|
|
r.tag = "#text"
|
|
r.where = t.where
|
|
r.keys = new []string
|
|
r.vals = new []UiExpr
|
|
r.on_keys = new []string
|
|
r.on_acts = new []UiAct
|
|
r.kids = new []UiTpl
|
|
r.text = ex_text(tpl_words(m.text), err)
|
|
push(t.kids, r)
|
|
} else { push(t.kids, tpl_read(ui_st, m, file)) }
|
|
}
|
|
}
|