ludic.ui, runtime, compiler: a component call's answer is written into a pooled record while the screen is built (call(p, name, args, into); value_into_*), a component root's passes pooled, an icon's atlas and name read in place; reseeded
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
862b048b17
commit
4d8526ad7e
10 changed files with 45701 additions and 45326 deletions
|
|
@ -45,7 +45,7 @@ function bd_pass_down(ui_st: mut UiState, n: UiNode, k: UiTpl, e: UiEnv) -> void
|
|||
}
|
||||
let id = tpl_attr(k, "id")
|
||||
if id != null { n.id = ui_eval_text(ui_st, id, e) }
|
||||
let up = new UiPass
|
||||
let up = up_take(ui_st)
|
||||
up.sheet = k.sheet
|
||||
up.style = k.style
|
||||
up.env = e
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export property UiClass {
|
|||
make: fn() -> pointer = null
|
||||
props: fn(pointer, Val) -> void = null
|
||||
model: fn(pointer, Val) -> Val = null # fills the object it is given (the instance keeps one)
|
||||
call: fn(pointer, string, Val) -> Val = null
|
||||
call: fn(pointer, string, Val, Val) -> Val = null # the last: where to write the answer, or null
|
||||
root: UiTpl = null # the template, once read
|
||||
sheet: UiSheet = null
|
||||
seen_xml: string = "" # the files as a developer's build last found them on disk
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ function env_set(ui_st: mut UiState, e: UiEnv, name: string, v: Val) -> void {
|
|||
if at.inst != null {
|
||||
let args = Value.list()
|
||||
Value.add(args, v)
|
||||
if Value.kind(at.inst.cls.call(at.inst.ptr, `set:{name}`, args)) != 99 { return }
|
||||
if Value.kind(at.inst.cls.call(at.inst.ptr, `set:{name}`, args, null)) != 99 { return }
|
||||
}
|
||||
if at.state != null and Value.has(at.state, name) != 0 {
|
||||
Value.put(at.state, name, v)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ function ev_call_with(ui_st: mut UiState, x: UiExpr, e: UiEnv, args: Val) -> Val
|
|||
var at = e
|
||||
while at != null {
|
||||
if at.inst != null {
|
||||
let r = at.inst.cls.call(at.inst.ptr, x.s, args)
|
||||
let r = at.inst.cls.call(at.inst.ptr, x.s, args, uv_hold(ui_st))
|
||||
if Value.kind(r) != 99 { return r }
|
||||
}
|
||||
at = at.parent
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ export property UiPool {
|
|||
envs1: []UiEnv = null
|
||||
un: int = 0
|
||||
ue: int = 0
|
||||
ups0: []UiPass = null # a component root's passes (bd_pass_down)
|
||||
ups1: []UiPass = null
|
||||
uu: int = 0
|
||||
vals0: []Val = null # what expressions work out while the screen is built (uv_new)
|
||||
vals1: []Val = null
|
||||
uv: int = 0
|
||||
|
|
@ -31,12 +34,15 @@ function pl_begin(ui_st: mut UiState, screen: string) -> void {
|
|||
p.envs1 = new []UiEnv
|
||||
p.vals0 = new []Val
|
||||
p.vals1 = new []Val
|
||||
p.ups0 = new []UiPass
|
||||
p.ups1 = new []UiPass
|
||||
push(ui_st.pl_pools, p)
|
||||
}
|
||||
p.gen = 1 - p.gen
|
||||
p.un = 0
|
||||
p.ue = 0
|
||||
p.uv = 0
|
||||
p.uu = 0
|
||||
ui_st.pl_cur = p
|
||||
}
|
||||
# a node, blank, with its own lists (empty) - from the pool when a build is under way
|
||||
|
|
@ -122,3 +128,33 @@ function uv_bool(ui_st: mut UiState, b: bool) -> Val {
|
|||
if b { return ui_st.uv_true }
|
||||
return ui_st.uv_false
|
||||
}
|
||||
# a pooled record as it is, for a call to write its answer into (a list keeps its items); null outside
|
||||
# a build, where what is answered may be kept
|
||||
function uv_hold(ui_st: mut UiState) -> Val {
|
||||
let p = ui_st.pl_cur
|
||||
if not ui_st.uv_on or p == null { return null }
|
||||
var list = p.vals0
|
||||
if p.gen == 1 { list = p.vals1 }
|
||||
if p.uv < len(list) {
|
||||
p.uv += 1
|
||||
return list[p.uv - 1]
|
||||
}
|
||||
let v = Value.null()
|
||||
push(list, v)
|
||||
p.uv += 1
|
||||
return v
|
||||
}
|
||||
function up_take(ui_st: mut UiState) -> UiPass {
|
||||
let p = ui_st.pl_cur
|
||||
if p == null { return new UiPass }
|
||||
var list = p.ups0
|
||||
if p.gen == 1 { list = p.ups1 }
|
||||
if p.uu < len(list) {
|
||||
p.uu += 1
|
||||
return list[p.uu - 1]
|
||||
}
|
||||
let u = new UiPass
|
||||
push(list, u)
|
||||
p.uu += 1
|
||||
return u
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,17 +45,11 @@ export function ui_image_reload(ui_st: mut UiState, path: string) -> void {
|
|||
}
|
||||
}
|
||||
function r3u_image(render3d_st: mut Render3dState, ui_st: mut UiState, src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
|
||||
var colon = -1
|
||||
for i in 0 .. len(src) {
|
||||
if colon < 0 and src[i] == 58 { colon = i }
|
||||
}
|
||||
if colon > 0 {
|
||||
let prefix: string = src[0..colon]
|
||||
for k in 0 .. len(ui_st.r3u_atlas) {
|
||||
if ui_st.r3u_atlas[k] == prefix {
|
||||
r3u_cell(render3d_st, ui_st, k, src[colon + 1..len(src)], x, y, w, h, c, a)
|
||||
return
|
||||
}
|
||||
for k in 0 .. len(ui_st.r3u_atlas) { # icon:NAME, the atlas and the name read in place
|
||||
let p = ui_st.r3u_atlas[k]
|
||||
if len(src) > len(p) and src[len(p)] == 58 and sat(src, 0, p) {
|
||||
r3u_cell(render3d_st, ui_st, k, src, len(p) + 1, x, y, w, h, c, a)
|
||||
return
|
||||
}
|
||||
}
|
||||
let t = r3u_tex(render3d_st, ui_st, src)
|
||||
|
|
@ -77,15 +71,17 @@ function r3u_is_cell(ui_st: UiState, src: string) -> bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
function r3u_cell(render3d_st: mut Render3dState, ui_st: mut UiState, k: int, name: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
|
||||
# the cell whose name is src from `at` on (compared where it stands), or its number
|
||||
function r3u_cell(render3d_st: mut Render3dState, ui_st: mut UiState, k: int, src: string, at: int, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
|
||||
let names = ui_st.r3u_atlas_names[k]
|
||||
let n = len(src) - at
|
||||
var idx = -1
|
||||
for i in 0 .. len(names) {
|
||||
if names[i] == name { idx = i }
|
||||
if len(names[i]) == n and sat(src, at, names[i]) { idx = i }
|
||||
}
|
||||
if idx < 0 and len(name) > 0 and name[0] >= 48 and name[0] <= 57 { idx = int(el_num(name)) }
|
||||
if idx < 0 and n > 0 and src[at] >= 48 and src[at] <= 57 { idx = int(el_num_in(src, at, len(src))) }
|
||||
if idx < 0 {
|
||||
ui_err(ui_st, `{ui_st.r3u_atlas[k]}:{name}: the atlas has no such picture`)
|
||||
ui_err(ui_st, `{src}: the atlas has no such picture`)
|
||||
return
|
||||
}
|
||||
let cols = ui_st.r3u_atlas_cols[k]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue