Merge branch 'lang/foundations' into lang/nav
This commit is contained in:
commit
a071196f89
51 changed files with 689 additions and 211 deletions
|
|
@ -53,10 +53,10 @@ program UiPointer {
|
|||
let active = down.children[2].bg
|
||||
let mid = said(down)
|
||||
frame(ui_st, hold.x + 5.0, hold.y + 90.0, false, 0.0, false)
|
||||
let off = frame(ui_st, -1.0, -1.0, false, 0.0, false)
|
||||
let off = said(frame(ui_st, -1.0, -1.0, false, 0.0, false))
|
||||
frame(ui_st, -1.0, -1.0, false, 0.0, true)
|
||||
let keyed = said(frame(ui_st, -1.0, -1.0, false, 0.0, true))
|
||||
let up = frame(ui_st, -1.0, -1.0, false, 0.0, false)
|
||||
print(`{ui_pointer_st.log}dragged {int(ui_pointer_st.dragged)} | {mid} active {active} | {said(off)} | {keyed} | {said(up)} {up.children[2].bg}`)
|
||||
print(`{ui_pointer_st.log}dragged {int(ui_pointer_st.dragged)} | {mid} active {active} | {off} | {keyed} | {said(up)} {up.children[2].bg}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ function an_apply(ui_st: mut UiState, n: UiNode) -> void {
|
|||
ui_err(ui_st, `animation {n.anim}: there is no @keyframes of that name`)
|
||||
return
|
||||
}
|
||||
var t = (an_now(ui_st) - an_began(ui_st, `{n.key}@{n.anim}`)) / n.anim_dur
|
||||
var t = (an_now(ui_st) - an_began(ui_st, mm_join(ui_st, n.key, "@", n.anim))) / n.anim_dur
|
||||
if n.anim_loop {
|
||||
let lap = int(t)
|
||||
t = t - float(lap)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
# attr.ludic - what a property sets, by its CSS name or the short one (width or w, background or
|
||||
# bg, font-size or size, ...). An attribute on an element is the same property, applied last.
|
||||
const AT_ALIAS: string = " width=w height=h min-width=min-w max-width=max-w min-height=min-h max-height=max-h padding=pad background=bg background-color=bg font-size=size opacity=alpha flex-grow=grow flex-shrink=shrink flex-direction=dir flex-wrap=wrap justify-content=justify align-items=align align-self=self row-gap=gap column-gap=gap text-align=talign "
|
||||
const AT_UNDRAWN: string = " font-weight font-family font-style box-shadow cursor transition animation letter-spacing text-decoration "
|
||||
# a stylesheet's property: one that means nothing is said
|
||||
function el_attr(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> void {
|
||||
|
|
@ -12,44 +11,57 @@ function el_apply(ui_st: mut UiState, n: UiNode, key: string, v0: Val) -> bool {
|
|||
let k = at_alias(key)
|
||||
ui_st.el_cur = n
|
||||
ui_st.el_key = k
|
||||
if len(k) > 2 and k[0..2] == "--" {
|
||||
cs_var_set(n, k, vl_text(v0))
|
||||
if len(k) > 2 and sat(k, 0, "--") {
|
||||
cs_var_set(n, k, vl_text_u(ui_st, v0))
|
||||
return true
|
||||
}
|
||||
let v = cs_vars_in(ui_st, n, v0)
|
||||
return el_size(ui_st, n, k, v) or el_box(ui_st, n, k, v) or el_flex(n, k, v) or el_look(ui_st, n, k, v) or el_place_prop(ui_st, n, k, v) or el_edge(ui_st, n, k, v) or el_more(ui_st, n, k, v)
|
||||
return el_size(ui_st, n, k, v) or el_box(ui_st, n, k, v) or el_flex(ui_st, n, k, v) or el_look(ui_st, n, k, v) or el_place_prop(ui_st, n, k, v) or el_edge(ui_st, n, k, v) or el_more(ui_st, n, k, v)
|
||||
}
|
||||
function at_alias(key: string) -> string {
|
||||
let pat = ` {key}=`
|
||||
let n = len(pat)
|
||||
for i in 0 .. len(AT_ALIAS) - n + 1 {
|
||||
if AT_ALIAS[i..i + n] == pat {
|
||||
var j = i + n
|
||||
while AT_ALIAS[j] != 32 { j += 1 }
|
||||
return AT_ALIAS[i + n..j]
|
||||
}
|
||||
}
|
||||
# the CSS name to the short one; literals, so asking allocates nothing (asked per rule per element)
|
||||
if key == "width" { return "w" }
|
||||
if key == "height" { return "h" }
|
||||
if key == "min-width" { return "min-w" }
|
||||
if key == "max-width" { return "max-w" }
|
||||
if key == "min-height" { return "min-h" }
|
||||
if key == "max-height" { return "max-h" }
|
||||
if key == "padding" { return "pad" }
|
||||
if key == "background" { return "bg" }
|
||||
if key == "background-color" { return "bg" }
|
||||
if key == "font-size" { return "size" }
|
||||
if key == "opacity" { return "alpha" }
|
||||
if key == "flex-grow" { return "grow" }
|
||||
if key == "flex-shrink" { return "shrink" }
|
||||
if key == "flex-direction" { return "dir" }
|
||||
if key == "flex-wrap" { return "wrap" }
|
||||
if key == "justify-content" { return "justify" }
|
||||
if key == "align-items" { return "align" }
|
||||
if key == "align-self" { return "self" }
|
||||
if key == "row-gap" { return "gap" }
|
||||
if key == "column-gap" { return "gap" }
|
||||
if key == "text-align" { return "talign" }
|
||||
return key
|
||||
}
|
||||
function el_size(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
if key == "w" or key == "h" { el_dim(ui_st, n, key == "w", v) } else if key == "min-w" { n.min_w = el_len(ui_st, v) } else if key == "max-w" { n.max_w = el_len(ui_st, v) } else if key == "min-h" { n.min_h = el_len(ui_st, v) } else if key == "max-h" { n.max_h = el_len(ui_st, v) } else if key == "gap" { n.gap = el_len(ui_st, v) } else { return false }
|
||||
return true
|
||||
}
|
||||
function el_flex(n: UiNode, key: string, v: Val) -> bool {
|
||||
let s = vl_text(v)
|
||||
function el_flex(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "dir" {
|
||||
n.dir = UI_COL
|
||||
if s == "row" { n.dir = UI_ROW }
|
||||
} else if key == "grow" { n.grow = el_num(s) } else if key == "flex" { el_flex_short(n, s) } else if key == "wrap" { n.wrap = s == "wrap" or (vl_truthy(v) and s != "false" and s != "nowrap") } else if key == "align" { n.align = el_place(v) } else if key == "self" { n.self = el_place(v) } else if key == "justify" { n.justify = el_place(v) } else if key == "talign" { n.talign = el_place(v) } else if key == "display" { n.hidden = s == "none" } else { return false }
|
||||
} else if key == "grow" { n.grow = el_num(s) } else if key == "flex" { el_flex_short(ui_st, n, s) } else if key == "wrap" { n.wrap = s == "wrap" or (vl_truthy(v) and s != "false" and s != "nowrap") } else if key == "align" { n.align = el_place(v) } else if key == "self" { n.self = el_place(v) } else if key == "justify" { n.justify = el_place(v) } else if key == "talign" { n.talign = el_place(v) } else if key == "display" { n.hidden = s == "none" } else { return false }
|
||||
return true
|
||||
}
|
||||
function el_look(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
let s = vl_text(v)
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "size" { n.size = el_len(ui_st, v) } else if key == "color" {
|
||||
n.fg = ui_color(ui_st, s)
|
||||
n.fg_a = ui_st.cl_alpha
|
||||
} else if key == "bg" {
|
||||
if gr_is(tpl_words(s)) { nx(n).grad = gr_parse(ui_st, s) } else if len(s) > 4 and s[0..4] == "url(" { n.bg_img = el_url(s) } else if tpl_words(s) == "transparent" {
|
||||
if gr_is(tpl_words(s)) { nx(n).grad = gr_parse(ui_st, s) } else if len(s) > 4 and sat(s, 0, "url(") { n.bg_img = el_url(s) } else if tpl_words(s) == "transparent" {
|
||||
n.bg = 0
|
||||
n.bg_a = 0.0
|
||||
} else {
|
||||
|
|
@ -64,7 +76,7 @@ function el_look(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
|||
}
|
||||
# border: 1 #ffcc00, or 1px solid accent
|
||||
function el_border(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
||||
let parts = lss_split(s, 32)
|
||||
let parts = mm_split(ui_st, s, 32)
|
||||
for i in 0 .. len(parts) {
|
||||
let p = parts[i]
|
||||
if len(p) > 0 and ((p[0] >= 48 and p[0] <= 57) or p[0] == 46) { el_sides_border(n, el_unit(ui_st, p)) } else if p == "none" { el_sides_border(n, 0.0) } else if len(p) > 0 and p != "solid" {
|
||||
|
|
|
|||
|
|
@ -18,25 +18,32 @@ function el_box(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
|||
}
|
||||
# top right bottom left out of 1 to 4 lengths
|
||||
function el_sides(ui_st: mut UiState, v: Val) -> void {
|
||||
let parts = new []float
|
||||
if vl_num(v) { push(parts, el_px(ui_st, Value.as_float(v))) } else {
|
||||
let words = el_words(vl_text(v))
|
||||
var n = 0
|
||||
if vl_num(v) {
|
||||
ui_st.el_s0 = el_px(ui_st, Value.as_float(v))
|
||||
n = 1
|
||||
} else {
|
||||
let words = mm_words(ui_st, vl_text_u(ui_st, v))
|
||||
for i in 0 .. len(words) {
|
||||
if len(words[i]) > 0 { push(parts, el_word_len(ui_st, words[i])) }
|
||||
if len(words[i]) > 0 and n < 4 {
|
||||
el_side_set(ui_st, n, el_word_len(ui_st, words[i]))
|
||||
n += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
while len(parts) < 4 {
|
||||
if len(parts) == 0 { push(parts, 0.0) } else if len(parts) == 1 { push(parts, parts[0]) } else if len(parts) == 2 { push(parts, parts[0]) } else { push(parts, parts[1]) }
|
||||
}
|
||||
ui_st.el_s0 = parts[0]
|
||||
ui_st.el_s1 = parts[1]
|
||||
ui_st.el_s2 = parts[2]
|
||||
ui_st.el_s3 = parts[3]
|
||||
if n == 0 { ui_st.el_s0 = 0.0 }
|
||||
if n < 2 { ui_st.el_s1 = ui_st.el_s0 }
|
||||
if n < 3 { ui_st.el_s2 = ui_st.el_s0 }
|
||||
if n < 4 { ui_st.el_s3 = ui_st.el_s1 }
|
||||
}
|
||||
# CSS's one to four sides, top right bottom left, without a list made for them
|
||||
function el_side_set(ui_st: mut UiState, i: int, v: float) -> void {
|
||||
if i == 0 { ui_st.el_s0 = v } else if i == 1 { ui_st.el_s1 = v } else if i == 2 { ui_st.el_s2 = v } else { ui_st.el_s3 = v }
|
||||
}
|
||||
# a length: a number, 10px, 1.5em, 2rem, 50vw, calc(...), fill, fit or auto (a percentage is el_pct's)
|
||||
function el_len(ui_st: mut UiState, v: Val) -> float {
|
||||
if vl_num(v) { return el_px(ui_st, Value.as_float(v)) }
|
||||
let s = vl_text(v)
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if s == "fill" { return UI_FILL }
|
||||
if ca_is(s) { return el_calc_len(ui_st, s) }
|
||||
if s == "fit" or s == "auto" or (len(s) > 0 and s[len(s) - 1] == 37) { return 0.0 }
|
||||
|
|
@ -67,8 +74,8 @@ function el_num(s: string) -> float {
|
|||
# start, center, end, stretch; for justify also between, around, evenly - with CSS's spellings
|
||||
function el_place(v: Val) -> int {
|
||||
var s = vl_text(v)
|
||||
if len(s) > 6 and s[0..6] == "space-" { s = s[6..len(s)] }
|
||||
if len(s) > 5 and s[0..5] == "flex-" { s = s[5..len(s)] }
|
||||
if len(s) > 6 and sat(s, 0, "space-") { s = s[6..len(s)] }
|
||||
if len(s) > 5 and sat(s, 0, "flex-") { s = s[5..len(s)] }
|
||||
if s == "center" { return UI_CENTER }
|
||||
if s == "end" or s == "right" { return UI_END }
|
||||
if s == "stretch" or s == "between" { return 3 }
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
# attr_edge.ludic - border-radius, outline (and its width, colour and offset), scrollbar-color
|
||||
function el_edge(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
let s = vl_text(v)
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "border-radius" { n.radius = el_len(ui_st, v) } else if key == "outline" { el_outline(ui_st, n, s) } else if key == "outline-width" { n.outline_w = el_len(ui_st, v) } else if key == "outline-offset" { n.outline_off = el_len(ui_st, v) } else if key == "outline-color" {
|
||||
n.outline_c = ui_color(ui_st, s)
|
||||
n.outline_a = ui_st.cl_alpha
|
||||
} else if key == "scrollbar-color" {
|
||||
let parts = lss_split(s, 32)
|
||||
let parts = mm_split(ui_st, s, 32)
|
||||
if len(parts) > 0 { n.bar_c = ui_color(ui_st, parts[0]) }
|
||||
if len(parts) > 1 { n.bar_track = ui_color(ui_st, parts[1]) }
|
||||
} else if key == "background-image" and gr_is(tpl_words(s)) { nx(n).grad = gr_parse(ui_st, s) } else if key == "background-image" { n.bg_img = el_url(s) } else if key == "border-image" { el_border_image(ui_st, n, s) } else if key == "box-shadow" { el_shadow(ui_st, n, s) } else if key == "animation" { el_animation(n, s) } else if key == "transition" { n.tr_dur = el_secs(s) } else { return false }
|
||||
} else if key == "background-image" and gr_is(tpl_words(s)) { nx(n).grad = gr_parse(ui_st, s) } else if key == "background-image" { n.bg_img = el_url(s) } else if key == "border-image" { el_border_image(ui_st, n, s) } else if key == "box-shadow" { el_shadow(ui_st, n, s) } else if key == "animation" { el_animation(ui_st, n, s) } else if key == "transition" { n.tr_dur = el_secs(s) } else { return false }
|
||||
return true
|
||||
}
|
||||
# url(path) or url("path") -> path
|
||||
function el_url(s: string) -> string {
|
||||
var t = tpl_words(s)
|
||||
if len(t) > 5 and t[0..4] == "url(" { t = tpl_words(t[4..len(t) - 1]) }
|
||||
if len(t) > 5 and sat(t, 0, "url(") { t = tpl_words(t[4..len(t) - 1]) }
|
||||
if len(t) >= 2 and (t[0] == 34 or t[0] == 39) { t = t[1..len(t) - 1] }
|
||||
if t == "none" { return "" }
|
||||
return t
|
||||
}
|
||||
# border-image: url(chip.png) 14 / 12px - the source's corner size, then how wide they are drawn
|
||||
function el_border_image(ui_st: UiState, n: UiNode, s: string) -> void {
|
||||
function el_border_image(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
||||
var close = 0
|
||||
while close < len(s) and s[close] != 41 { close += 1 }
|
||||
n.bi_src = el_url(s[0..Math.min(close + 1, len(s))])
|
||||
let rest = lss_split(s[Math.min(close + 1, len(s))..len(s)], 47)
|
||||
let rest = mm_split(ui_st, s[Math.min(close + 1, len(s))..len(s)], 47)
|
||||
n.bi_slice = el_num(tpl_words(rest[0]))
|
||||
n.bi_width = el_px(ui_st, n.bi_slice)
|
||||
if len(rest) > 1 { n.bi_width = el_unit(ui_st, tpl_words(rest[1])) }
|
||||
|
|
@ -35,7 +35,7 @@ function el_shadow(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
|||
n.sh_c = -2
|
||||
return
|
||||
}
|
||||
let parts = lss_split(s, 32)
|
||||
let parts = mm_split(ui_st, s, 32)
|
||||
var nums = 0
|
||||
var col = ""
|
||||
for i in 0 .. len(parts) {
|
||||
|
|
@ -53,7 +53,7 @@ function el_shadow(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
|||
}
|
||||
# outline: 2px solid #ffcc00, or none
|
||||
function el_outline(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
||||
let parts = lss_split(s, 32)
|
||||
let parts = mm_split(ui_st, s, 32)
|
||||
n.outline_w = 0.0
|
||||
for i in 0 .. len(parts) {
|
||||
let p = parts[i]
|
||||
|
|
@ -64,8 +64,8 @@ function el_outline(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
|||
}
|
||||
}
|
||||
# animation: fade 0.25s infinite alternate
|
||||
function el_animation(n: UiNode, s: string) -> void {
|
||||
let parts = lss_split(s, 32)
|
||||
function el_animation(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
||||
let parts = mm_split(ui_st, s, 32)
|
||||
n.anim = ""
|
||||
for i in 0 .. len(parts) {
|
||||
let p = parts[i]
|
||||
|
|
@ -78,7 +78,7 @@ function el_secs(s: string) -> float {
|
|||
for i in 0 .. len(parts) {
|
||||
let p = parts[i]
|
||||
if len(p) > 1 and p[0] >= 48 and p[0] <= 57 or len(p) > 1 and p[0] == 46 {
|
||||
if len(p) > 2 and p[len(p) - 2..len(p)] == "ms" { return el_num(p) / 1000.0 }
|
||||
if len(p) > 2 and sat(p, len(p) - 2, "ms") { return el_num(p) / 1000.0 }
|
||||
return el_num(p)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# for pictures and natives, zoom (zoom.ludic), and a list split at its top-level commas
|
||||
function el_fit_props(ui_st: mut UiState, n: UiNode, key: string, s: string) -> bool {
|
||||
if key == "aspect-ratio" {
|
||||
let parts = lss_split(s, 47)
|
||||
let parts = mm_split(ui_st, s, 47)
|
||||
var r = el_num(tpl_words(parts[0]))
|
||||
if len(parts) > 1 and el_num(tpl_words(parts[1])) > 0.0 { r = r / el_num(tpl_words(parts[1])) }
|
||||
if tpl_words(s) == "auto" { r = 0.0 }
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# percentage is kept apart and taken of the containing block's width (left, right) or height (top,
|
||||
# bottom) when the element is placed
|
||||
function el_inset(ui_st: mut UiState, n: UiNode, side: int, v: Val) -> float {
|
||||
let s = vl_text(v)
|
||||
let s = vl_text_u(ui_st, v)
|
||||
var pct = 0.0
|
||||
var px = UI_AUTO
|
||||
if s != "auto" {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# attr_more.ludic - width and height (where 0 is 0 and calc() may hold a percentage), the flex
|
||||
# shorthand, flex-shrink, order, text-shadow, pointer-events, text-fit and line-height (text_fit.ludic)
|
||||
function el_more(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
let s = vl_text(v)
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "shrink" { nx(n).shrink = Math.max(el_num(s), 0.0) } else if key == "order" { nx(n).order = int(el_num(s)) } else if key == "text-shadow" { el_text_shadow(ui_st, n, s) } else if key == "pointer-events" { nx(n).no_pointer = tpl_words(s) == "none" } else if key == "text-fit" { el_text_fit(ui_st, n, s) } else if key == "line-height" { el_line_h(ui_st, n, s) } else { return el_fit_props(ui_st, n, key, s) }
|
||||
return true
|
||||
}
|
||||
# width or height: a length (0 included), fill, a percentage, calc(), or auto/fit (none)
|
||||
function el_dim(ui_st: mut UiState, n: UiNode, wide: bool, v: Val) -> void {
|
||||
let s = vl_text(v)
|
||||
let s = vl_text_u(ui_st, v)
|
||||
var fixed = UI_AUTO
|
||||
var pct = 0.0
|
||||
var off = 0.0
|
||||
|
|
@ -40,8 +40,8 @@ function el_calc_len(ui_st: mut UiState, s: string) -> float {
|
|||
return ui_st.ca_px
|
||||
}
|
||||
# flex: 1 | flex: 1 0 | flex: 2 1 auto | flex: none - the grow, then the shrink
|
||||
function el_flex_short(n: UiNode, s: string) -> void {
|
||||
let parts = el_words(s)
|
||||
function el_flex_short(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
||||
let parts = mm_words(ui_st, s)
|
||||
if s == "none" {
|
||||
n.grow = 0.0
|
||||
nx(n).shrink = 0.0
|
||||
|
|
@ -72,7 +72,7 @@ function el_text_shadow(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
|||
x.tsh_set = true
|
||||
x.tsh_c = -2
|
||||
if tpl_words(s) == "none" { return }
|
||||
let parts = el_words(s)
|
||||
let parts = mm_words(ui_st, s)
|
||||
var nums = 0
|
||||
var col = ""
|
||||
for i in 0 .. len(parts) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# attr_place.ludic - position and its insets, z-index, overflow, white-space and text-overflow
|
||||
function el_place_prop(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
let s = vl_text(v)
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "position" {
|
||||
n.pos = 0
|
||||
if s == "relative" { n.pos = 1 }
|
||||
|
|
|
|||
|
|
@ -32,6 +32,19 @@ function ui_default_backend() -> UiBackend {
|
|||
return UiRenderers[0].make()
|
||||
}
|
||||
export state UiState {
|
||||
pl_pools: []UiPool = new []UiPool # pool.ludic: each screen's nodes and envs, used again
|
||||
pl_cur: UiPool = null
|
||||
mm: UiMemo = null # memo.ludic: splits, gradients and keys by their text
|
||||
mm_ints: []string = null
|
||||
mm_ivals: []Val = null
|
||||
ev_depth: int = 0 # eval.ludic: a call's arguments, in lists kept one a depth
|
||||
ev_args: []Val = new []Val
|
||||
ly_depth: int = 0 # layout_run.ludic: the lists a line lays out with, one a depth
|
||||
ly_sizes: [][]float = new [][]float
|
||||
ly_frozen: [][]bool = new [][]bool
|
||||
cs_rules: []UiRule = new []UiRule # cascade_merge.ludic: a component root's rules, gathered
|
||||
cs_envs: []UiEnv = new []UiEnv
|
||||
cs_seen: []UiSheet = new []UiSheet
|
||||
an_frames: []UiKeyframes = new []UiKeyframes
|
||||
an_keys: []string = new []string
|
||||
an_start: []float = new []float
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ function bd_kids(ui_st: mut UiState, kids: []UiTpl, e0: UiEnv, key: string, out:
|
|||
for i in 0 .. len(kids) {
|
||||
let k = kids[i]
|
||||
ui_st.ui_at = k.where
|
||||
let ck = `{key}/{i}`
|
||||
let ck = mm_join(ui_st, key, "/", mm_int(ui_st, i))
|
||||
if k.tag == "state" or k.tag == "style" { continue }
|
||||
if k.tag == "let" {
|
||||
e = bd_let(ui_st, k, e)
|
||||
|
|
@ -47,12 +47,12 @@ function bd_each(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []UiN
|
|||
let at_name = bd_name(k, "index", "index")
|
||||
let by = tpl_attr(k, "key")
|
||||
for j in 0 .. Value.count(list) {
|
||||
let le = env_new(e)
|
||||
let le = env_new(ui_st, e)
|
||||
env_bind(le, as_name, Value.at(list, j))
|
||||
env_bind(le, at_name, Value.int(j))
|
||||
var id = string(j)
|
||||
env_bind(le, at_name, mm_ival(ui_st, j))
|
||||
var id = mm_int(ui_st, j)
|
||||
if by != null { id = ui_eval_text(ui_st, by, le) }
|
||||
bd_kids(ui_st, k.kids, le, `{key}#{id}`, out)
|
||||
bd_kids(ui_st, k.kids, le, mm_join(ui_st, key, "#", id), out)
|
||||
}
|
||||
}
|
||||
# <slot/> is what the component's user put inside it; <slot name="x"/> their <template slot="x">
|
||||
|
|
@ -77,7 +77,7 @@ function bd_comp(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []UiN
|
|||
}
|
||||
if k.comp == null { return false }
|
||||
let c = k.comp
|
||||
let ce = env_new(null)
|
||||
let ce = env_new(ui_st, null)
|
||||
ce.model = e.model
|
||||
ce.ctx = e.ctx
|
||||
for i in 0 .. len(c.keys) {
|
||||
|
|
@ -86,7 +86,6 @@ function bd_comp(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []UiN
|
|||
for i in 0 .. len(k.keys) { env_bind(ce, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
|
||||
ce.on_names = k.on_keys
|
||||
ce.on_acts = k.on_acts
|
||||
ce.on_envs = new []UiEnv
|
||||
for i in 0 .. len(k.on_keys) { push(ce.on_envs, e) }
|
||||
ce.slot = k
|
||||
ce.slot_env = e
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@ function bd_class(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []Ui
|
|||
let cls = k.cls
|
||||
uc_load(ui_st, cls)
|
||||
let it = in_get(ui_st, key, cls)
|
||||
let props = Value.object()
|
||||
if it.props == null { it.props = Value.object() }
|
||||
let props = it.props
|
||||
Value.clear(props)
|
||||
for i in 0 .. len(k.keys) {
|
||||
let a = k.keys[i]
|
||||
if a != "class" and a != "style" and a != "id" { Value.put(props, a, ui_eval(ui_st, k.vals[i], e)) }
|
||||
}
|
||||
cls.props(it.ptr, props)
|
||||
let ce = env_new(null)
|
||||
let ce = env_new(ui_st, null)
|
||||
ce.model = cls.model(it.ptr)
|
||||
ce.inst = it
|
||||
ce.ctx = e.ctx
|
||||
|
|
@ -19,7 +21,6 @@ function bd_class(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []Ui
|
|||
ce.slot_env = e
|
||||
ce.on_names = k.on_keys
|
||||
ce.on_acts = k.on_acts
|
||||
ce.on_envs = new []UiEnv
|
||||
for i in 0 .. len(k.on_keys) { push(ce.on_envs, e) }
|
||||
lc_note(ui_st, key, k.on_keys, k.on_acts, e)
|
||||
let at = len(out)
|
||||
|
|
@ -33,7 +34,7 @@ function bd_class(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []Ui
|
|||
function bd_pass_down(ui_st: mut UiState, n: UiNode, k: UiTpl, e: UiEnv) -> void {
|
||||
let c = tpl_attr(k, "class")
|
||||
if c != null {
|
||||
let parts = lss_split(ui_eval_text(ui_st, c, e), 32)
|
||||
let parts = mm_split(ui_st, ui_eval_text(ui_st, c, e), 32)
|
||||
for i in 0 .. len(parts) {
|
||||
if len(parts[i]) > 0 { push(n.classes, parts[i]) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
# build_more.ludic - <let name="{value}"/> names a value for the siblings after it, and
|
||||
# <provide name="{value}"> gives it to everything inside, components included (React's context)
|
||||
function bd_let(ui_st: mut UiState, k: UiTpl, e: UiEnv) -> UiEnv {
|
||||
let le = env_new(e)
|
||||
let le = env_new(ui_st, e)
|
||||
for i in 0 .. len(k.keys) { env_bind(le, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
|
||||
return le
|
||||
}
|
||||
function bd_provide(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
|
||||
let cx = env_new(e.ctx)
|
||||
let cx = env_new(ui_st, e.ctx)
|
||||
for i in 0 .. len(k.keys) { env_bind(cx, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
|
||||
let pe = env_new(e)
|
||||
let pe = env_new(ui_st, e)
|
||||
pe.ctx = cx
|
||||
bd_kids(ui_st, k.kids, pe, key, out)
|
||||
}
|
||||
|
|
@ -18,12 +18,11 @@ function bd_group(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []Ui
|
|||
bd_kids(ui_st, k.kids, e, key, out)
|
||||
return
|
||||
}
|
||||
let t = new UiNode
|
||||
let t = nd_take(ui_st)
|
||||
t.kind = UI_TEXT
|
||||
t.key = key
|
||||
t.text = ui_tr(ui_st, ui_eval_text(ui_st, k.text, e))
|
||||
t.env = e
|
||||
t.children = new []UiNode
|
||||
push(out, t)
|
||||
}
|
||||
# text inside text - <p>Hi <b>there</b></p>, <h3><slot/></h3> - reads as one line of it
|
||||
|
|
@ -37,5 +36,5 @@ function el_inline(n: UiNode) -> void {
|
|||
s = s + c.text
|
||||
}
|
||||
n.text = s
|
||||
n.children = new []UiNode
|
||||
List.clear(n.children)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ function ca_fn_at(s: string, at: int) -> string {
|
|||
if ca_word(s, at, "clamp(") { return "clamp" }
|
||||
return ""
|
||||
}
|
||||
function ca_word(s: string, at: int, w: string) -> bool { return at + len(w) <= len(s) and s[at..at + len(w)] == w }
|
||||
function ca_word(s: string, at: int, w: string) -> bool { return at + len(w) <= len(s) and sat(s, at, w) }
|
||||
function ca_fn(ui_st: mut UiState, f: string) -> CaVal {
|
||||
ui_st.ca_i = ui_st.ca_i + len(f) + 1
|
||||
let args = new []CaVal
|
||||
|
|
|
|||
|
|
@ -9,11 +9,14 @@ function cs_tree(ui_st: mut UiState, n: UiNode) -> void {
|
|||
}
|
||||
if n.tag != "" { cs_node(ui_st, n) }
|
||||
for i in 0 .. len(n.children) { cs_tree(ui_st, n.children[i]) }
|
||||
var shown = new []UiNode
|
||||
var kept = 0
|
||||
for i in 0 .. len(n.children) {
|
||||
if not n.children[i].hidden { push(shown, n.children[i]) }
|
||||
if not n.children[i].hidden {
|
||||
n.children[kept] = n.children[i]
|
||||
kept += 1
|
||||
}
|
||||
}
|
||||
n.children = shown
|
||||
while len(n.children) > kept { List.pop(n.children) }
|
||||
cs_order(n)
|
||||
}
|
||||
# twice: the font size (and zoom) first, from every rule, so an em anywhere reads the size the
|
||||
|
|
@ -51,10 +54,10 @@ function cs_rule(ui_st: mut UiState, n: UiNode, r: UiRule) -> void { cs_rule_in(
|
|||
# a rule's custom properties first, so its other declarations can read them; values read in `e`
|
||||
function cs_rule_in(ui_st: mut UiState, n: UiNode, r: UiRule, e: UiEnv) -> void {
|
||||
for j in 0 .. len(r.keys) {
|
||||
if len(r.keys[j]) > 2 and r.keys[j][0..2] == "--" { el_attr(ui_st, n, r.keys[j], ui_eval(ui_st, r.vals[j], e)) }
|
||||
if len(r.keys[j]) > 2 and sat(r.keys[j], 0, "--") { el_attr(ui_st, n, r.keys[j], ui_eval(ui_st, r.vals[j], e)) }
|
||||
}
|
||||
for j in 0 .. len(r.keys) {
|
||||
if not (len(r.keys[j]) > 2 and r.keys[j][0..2] == "--") and cs_pass_ok(ui_st, r.keys[j]) { el_attr(ui_st, n, r.keys[j], ui_eval(ui_st, r.vals[j], e)) }
|
||||
if not (len(r.keys[j]) > 2 and sat(r.keys[j], 0, "--")) and cs_pass_ok(ui_st, r.keys[j]) { el_attr(ui_st, n, r.keys[j], ui_eval(ui_st, r.vals[j], e)) }
|
||||
}
|
||||
}
|
||||
function ua_sheet(ui_st: mut UiState) -> UiSheet {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@
|
|||
# specificity as one sheet's are. On a tie the user's rule wins (the outermost user's last), as a
|
||||
# later rule does. Then `order`, which rearranges a flex box's children without touching the tree.
|
||||
function cs_merged(ui_st: mut UiState, n: UiNode) -> void {
|
||||
let rules = new []UiRule
|
||||
let envs = new []UiEnv
|
||||
let seen = new []UiSheet
|
||||
let rules = ui_st.cs_rules # kept and emptied: a merge runs once an element, never inside another
|
||||
let envs = ui_st.cs_envs
|
||||
let seen = ui_st.cs_seen
|
||||
List.clear(rules)
|
||||
List.clear(envs)
|
||||
List.clear(seen)
|
||||
if n.sheet != null { cs_gather(ui_st, n, n.sheet, n.env, rules, envs, seen) }
|
||||
for i in 0 .. len(n.ups) {
|
||||
if n.ups[i].sheet != null { cs_gather(ui_st, n, n.ups[i].sheet, n.ups[i].env, rules, envs, seen) }
|
||||
|
|
|
|||
|
|
@ -5,12 +5,11 @@ function ui_color(ui_st: mut UiState, name0: string) -> int {
|
|||
let name = tpl_words(name0)
|
||||
ui_st.cl_alpha = 1.0
|
||||
if name == "none" or name == "" or name == "transparent" { return UI_NONE }
|
||||
if name[0] == 35 { return cl_hex(ui_st, name[1..len(name)]) }
|
||||
if len(name) > 4 and (name[0..4] == "rgb(" or name[0..5] == "rgba(") { return cl_rgb(ui_st, name) }
|
||||
let pat = ` {name}=`
|
||||
let n = len(pat)
|
||||
for i in 0 .. len(CL_NAMES) - n + 1 {
|
||||
if CL_NAMES[i..i + n] == pat { return cl_hex(ui_st, CL_NAMES[i + n..i + n + 6]) }
|
||||
if name[0] == 35 { return cl_hex_at(ui_st, name, 1, len(name) - 1) }
|
||||
if len(name) > 4 and (sat(name, 0, "rgb(") or sat(name, 0, "rgba(")) { return cl_rgb(ui_st, name) }
|
||||
let n = len(name)
|
||||
for i in 0 .. len(CL_NAMES) - n - 1 {
|
||||
if CL_NAMES[i] == 32 and CL_NAMES[i + n + 1] == 61 and sat(CL_NAMES, i + 1, name) { return cl_hex_at(ui_st, CL_NAMES, i + n + 2, 6) }
|
||||
}
|
||||
ui_err(ui_st, `{name}: not a colour - #rrggbb, rgb(), rgba(), a name, or var(--a-colour)`)
|
||||
return 15658734
|
||||
|
|
@ -20,23 +19,24 @@ function cl_digit(c: int) -> int {
|
|||
if c >= 65 { return c - 55 }
|
||||
return c - 48
|
||||
}
|
||||
function cl_hex(ui_st: mut UiState, h: string) -> int {
|
||||
function cl_hex(ui_st: mut UiState, h: string) -> int { return cl_hex_at(ui_st, h, 0, len(h)) }
|
||||
# the n hex digits of `s` from `at`, read where they stand
|
||||
function cl_hex_at(ui_st: mut UiState, s: string, at: int, n: int) -> int {
|
||||
var c = 0
|
||||
let n = len(h)
|
||||
if n == 3 or n == 4 {
|
||||
for i in 0 .. 3 { c = c * 256 + cl_digit(h[i]) * 17 }
|
||||
if n == 4 { ui_st.cl_alpha = float(cl_digit(h[3]) * 17) / 255.0 }
|
||||
for i in 0 .. 3 { c = c * 256 + cl_digit(s[at + i]) * 17 }
|
||||
if n == 4 { ui_st.cl_alpha = float(cl_digit(s[at + 3]) * 17) / 255.0 }
|
||||
return c
|
||||
}
|
||||
for i in 0 .. 3 { c = c * 256 + cl_digit(h[i * 2]) * 16 + cl_digit(h[i * 2 + 1]) }
|
||||
if n == 8 { ui_st.cl_alpha = float(cl_digit(h[6]) * 16 + cl_digit(h[7])) / 255.0 }
|
||||
for i in 0 .. 3 { c = c * 256 + cl_digit(s[at + i * 2]) * 16 + cl_digit(s[at + i * 2 + 1]) }
|
||||
if n == 8 { ui_st.cl_alpha = float(cl_digit(s[at + 6]) * 16 + cl_digit(s[at + 7])) / 255.0 }
|
||||
return c
|
||||
}
|
||||
# rgb(217, 165, 74) or rgba(0, 0, 0, 0.55)
|
||||
function cl_rgb(ui_st: mut UiState, s: string) -> int {
|
||||
var open = 0
|
||||
while open < len(s) and s[open] != 40 { open += 1 }
|
||||
let parts = lss_split(s[open + 1..len(s) - 1], 44)
|
||||
let parts = mm_split(ui_st, s[open + 1..len(s) - 1], 44)
|
||||
var c = 0
|
||||
for i in 0 .. Math.min(3, len(parts)) { c = c * 256 + Math.clamp(int(el_num(tpl_words(parts[i]))), 0, 255) }
|
||||
if len(parts) > 3 { ui_st.cl_alpha = el_num(tpl_words(parts[3])) }
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@
|
|||
# input[type=text|number|key] .ui-label .ui-field > .ui-value (+ .ui-caret while focused)
|
||||
# select .ui-label .ui-prev .ui-value .ui-next (its <option>s hidden)
|
||||
# with a note="...", the label is .ui-labels > .ui-label + .ui-note
|
||||
function ct_part(n: UiNode, cls: string, text: string) -> UiNode {
|
||||
let p = new UiNode
|
||||
p.key = `{n.key}/{cls}`
|
||||
function ct_part(ui_st: mut UiState, n: UiNode, cls: string, text: string) -> UiNode {
|
||||
let p = nd_take(ui_st)
|
||||
p.key = mm_join(ui_st, n.key, "/", cls)
|
||||
p.tag = "span"
|
||||
p.env = n.env
|
||||
p.sheet = n.sheet
|
||||
p.children = new []UiNode
|
||||
p.classes = new []string
|
||||
push(p.classes, cls)
|
||||
p.akeys = new []string
|
||||
p.avals = new []string
|
||||
p.vals = new []Val
|
||||
if text != "" {
|
||||
p.kind = UI_TEXT
|
||||
p.text = text
|
||||
|
|
@ -23,18 +18,18 @@ function ct_part(n: UiNode, cls: string, text: string) -> UiNode {
|
|||
return p
|
||||
}
|
||||
# <progress value max> and <meter value min max>: a track with a fill as far as the value
|
||||
function ct_build_bar(n: UiNode) -> void {
|
||||
function ct_build_bar(ui_st: mut UiState, n: UiNode) -> void {
|
||||
n.dir = UI_ROW
|
||||
let lo = Value.as_float(ui_attr(n, "min"))
|
||||
var hi = Value.as_float(ui_attr(n, "max"))
|
||||
if hi <= lo { hi = lo + 1.0 }
|
||||
let fill = ct_part(n, "ui-fill", "")
|
||||
let fill = ct_part(ui_st, n, "ui-fill", "")
|
||||
fill.w_pct = Math.clamp((Value.as_float(ui_attr(n, "value")) - lo) / (hi - lo), 0.0, 1.0) * 100.0
|
||||
push(n.children, fill)
|
||||
}
|
||||
function ct_build(ui_st: UiState, n: UiNode) -> void {
|
||||
function ct_build(ui_st: mut UiState, n: UiNode) -> void {
|
||||
if n.tag == "progress" or n.tag == "meter" {
|
||||
ct_build_bar(n)
|
||||
ct_build_bar(ui_st, n)
|
||||
return
|
||||
}
|
||||
n.dir = UI_ROW
|
||||
|
|
@ -46,41 +41,41 @@ function ct_build(ui_st: UiState, n: UiNode) -> void {
|
|||
}
|
||||
ct_label(ui_st, n)
|
||||
if t == "checkbox" or t == "radio" {
|
||||
let track = ct_part(n, "ui-track", "")
|
||||
push(track.children, ct_part(n, "ui-knob", ""))
|
||||
let track = ct_part(ui_st, n, "ui-track", "")
|
||||
push(track.children, ct_part(ui_st, n, "ui-knob", ""))
|
||||
push(n.children, track)
|
||||
} else if t == "range" {
|
||||
ct_build_range(n)
|
||||
ct_build_range(ui_st, n)
|
||||
} else {
|
||||
let field = ct_part(n, "ui-field", "")
|
||||
push(field.children, ct_part(n, "ui-value", ct_field_text(ui_st, n)))
|
||||
if ui_st.fc_key == n.key and t != "key" { push(field.children, ct_part(n, "ui-caret", "")) }
|
||||
let field = ct_part(ui_st, n, "ui-field", "")
|
||||
push(field.children, ct_part(ui_st, n, "ui-value", ct_field_text(ui_st, n)))
|
||||
if ui_st.fc_key == n.key and t != "key" { push(field.children, ct_part(ui_st, n, "ui-caret", "")) }
|
||||
push(n.children, field)
|
||||
}
|
||||
}
|
||||
function ct_build_range(n: UiNode) -> void {
|
||||
function ct_build_range(ui_st: mut UiState, n: UiNode) -> void {
|
||||
let lo = Value.as_float(ui_attr(n, "min"))
|
||||
var hi = Value.as_float(ui_attr(n, "max"))
|
||||
if hi <= lo { hi = lo + 1.0 }
|
||||
let v = Value.as_float(ui_attr(n, "value"))
|
||||
let track = ct_part(n, "ui-track", "")
|
||||
let fill = ct_part(n, "ui-fill", "")
|
||||
let track = ct_part(ui_st, n, "ui-track", "")
|
||||
let fill = ct_part(ui_st, n, "ui-fill", "")
|
||||
fill.w_pct = Math.clamp((v - lo) / (hi - lo), 0.0, 1.0) * 100.0
|
||||
push(track.children, fill)
|
||||
push(track.children, ct_part(n, "ui-thumb", ""))
|
||||
push(track.children, ct_part(ui_st, n, "ui-thumb", ""))
|
||||
push(n.children, track)
|
||||
push(n.children, ct_part(n, "ui-value", ct_value_text(n)))
|
||||
push(n.children, ct_part(ui_st, n, "ui-value", ct_value_text(n)))
|
||||
}
|
||||
function ct_build_select(ui_st: UiState, n: UiNode) -> void {
|
||||
function ct_build_select(ui_st: mut UiState, n: UiNode) -> void {
|
||||
let opts = n.children
|
||||
n.children = new []UiNode
|
||||
ct_label(ui_st, n)
|
||||
var shown = ""
|
||||
let at = ct_option_at(n, opts)
|
||||
if at >= 0 { shown = opts[at].text }
|
||||
push(n.children, ct_part(n, "ui-prev", "<"))
|
||||
push(n.children, ct_part(n, "ui-value", shown))
|
||||
push(n.children, ct_part(n, "ui-next", ">"))
|
||||
push(n.children, ct_part(ui_st, n, "ui-prev", "<"))
|
||||
push(n.children, ct_part(ui_st, n, "ui-value", shown))
|
||||
push(n.children, ct_part(ui_st, n, "ui-next", ">"))
|
||||
n.opts = opts
|
||||
}
|
||||
# which option the select's value names: an option's value="...", else its place
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
# controls_parts.ludic - what a control shows besides its own parts: its label, with a `note` (a line
|
||||
# of help under it) in .ui-labels > .ui-label + .ui-note, and a range's or a number's value as text:
|
||||
# `decimals="1"` places, `format="percent"` its place between min and max, and a `unit` after it
|
||||
function ct_label(ui_st: UiState, n: UiNode) -> void {
|
||||
function ct_label(ui_st: mut UiState, n: UiNode) -> void {
|
||||
let label = ui_attr_text(n, "label")
|
||||
let note = ui_attr_text(n, "note")
|
||||
if note == "" {
|
||||
if label != "" { push(n.children, ct_part(n, "ui-label", ui_tr(ui_st, label))) }
|
||||
if label != "" { push(n.children, ct_part(ui_st, n, "ui-label", ui_tr(ui_st, label))) }
|
||||
return
|
||||
}
|
||||
let both = ct_part(n, "ui-labels", "")
|
||||
if label != "" { push(both.children, ct_part(n, "ui-label", ui_tr(ui_st, label))) }
|
||||
push(both.children, ct_part(n, "ui-note", ui_tr(ui_st, note)))
|
||||
let both = ct_part(ui_st, n, "ui-labels", "")
|
||||
if label != "" { push(both.children, ct_part(ui_st, n, "ui-label", ui_tr(ui_st, label))) }
|
||||
push(both.children, ct_part(ui_st, n, "ui-note", ui_tr(ui_st, note)))
|
||||
push(n.children, both)
|
||||
}
|
||||
function ct_value_text(n: UiNode) -> string {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,18 @@ export property UiGradient {
|
|||
alphas: []float = null
|
||||
at: []float = null # each stop's place, 0 to 1
|
||||
}
|
||||
function gr_is(s: string) -> bool { return len(s) > 16 and s[0..16] == "linear-gradient(" }
|
||||
function gr_is(s: string) -> bool { return len(s) > 16 and sat(s, 0, "linear-gradient(") }
|
||||
# a gradient is parsed once per text and shared by every element that wears it - never changed after
|
||||
function gr_parse(ui_st: mut UiState, s0: string) -> UiGradient {
|
||||
let m = mm_of(ui_st)
|
||||
let i = mm_find(m, MM_GRAD, s0)
|
||||
if i >= 0 { return m.grads[i] }
|
||||
let g = gr_parse_new(ui_st, s0)
|
||||
let j = mm_add(m, MM_GRAD, s0)
|
||||
if j >= 0 { m.grads[j] = g }
|
||||
return g
|
||||
}
|
||||
function gr_parse_new(ui_st: mut UiState, s0: string) -> UiGradient {
|
||||
let s = tpl_words(s0)
|
||||
let parts = el_commas(s[16..len(s) - 1])
|
||||
let g = new UiGradient
|
||||
|
|
@ -18,7 +28,7 @@ function gr_parse(ui_st: mut UiState, s0: string) -> UiGradient {
|
|||
var from = 0
|
||||
if len(parts) > 0 and gr_dir(g, tpl_words(parts[0])) { from = 1 }
|
||||
for i in from .. len(parts) {
|
||||
let words = el_words(tpl_words(parts[i]))
|
||||
let words = mm_words(ui_st, tpl_words(parts[i]))
|
||||
var col = tpl_words(parts[i])
|
||||
var at = -1.0
|
||||
let last = words[len(words) - 1]
|
||||
|
|
@ -36,7 +46,7 @@ function gr_parse(ui_st: mut UiState, s0: string) -> UiGradient {
|
|||
return g
|
||||
}
|
||||
function gr_dir(g: UiGradient, w: string) -> bool {
|
||||
if w == "to bottom" { g.dir = 0 } else if w == "to top" { g.dir = 1 } else if w == "to right" { g.dir = 2 } else if w == "to left" { g.dir = 3 } else if len(w) > 3 and w[len(w) - 3..len(w)] == "deg" {
|
||||
if w == "to bottom" { g.dir = 0 } else if w == "to top" { g.dir = 1 } else if w == "to right" { g.dir = 2 } else if w == "to left" { g.dir = 3 } else if len(w) > 3 and sat(w, len(w) - 3, "deg") {
|
||||
let d = int(Math.round(el_num(w) / 90.0)) % 4
|
||||
g.dir = 1
|
||||
if d == 1 or d == -3 { g.dir = 2 }
|
||||
|
|
|
|||
|
|
@ -4,19 +4,14 @@ const EL_BOXES: string = " col div progress meter section header footer nav main
|
|||
const EL_TEXTS: string = " text span p label h1 h2 h3 h4 h5 h6 strong em small b i a option "
|
||||
function bd_elem(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string) -> UiNode {
|
||||
ui_st.ui_at = k.where
|
||||
let n = new UiNode
|
||||
let n = nd_take(ui_st)
|
||||
n.key = key
|
||||
n.tag = k.tag
|
||||
n.env = e
|
||||
n.sheet = k.sheet
|
||||
n.style = k.style
|
||||
n.children = new []UiNode
|
||||
n.classes = new []string
|
||||
n.akeys = new []string
|
||||
n.avals = new []string
|
||||
n.vals = new []Val
|
||||
el_kind(ui_st, n, k.tag)
|
||||
for i in 0 .. len(k.keys) { el_keep(n, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
|
||||
for i in 0 .. len(k.keys) { el_keep(ui_st, n, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
|
||||
n.hovered = fr_was_hovered(ui_st, key)
|
||||
n.on_names = k.on_keys
|
||||
n.on_acts = k.on_acts
|
||||
|
|
@ -28,7 +23,7 @@ function bd_elem(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string) -> UiNode
|
|||
let say = ui_attr_text(n, "translate")
|
||||
if say == "no" { ui_st.tr_no = true } else if say == "yes" { ui_st.tr_no = false }
|
||||
bd_kids(ui_st, k.kids, e, key, n.children)
|
||||
if k.text != null { el_text(n, ui_tr(ui_st, ui_eval_text(ui_st, k.text, e))) }
|
||||
if k.text != null { el_text(ui_st, n, ui_tr(ui_st, ui_eval_text(ui_st, k.text, e))) }
|
||||
el_inline(n)
|
||||
if k.tag == "input" or k.tag == "select" or k.tag == "progress" or k.tag == "meter" { ct_build(ui_st, n) }
|
||||
ui_st.tr_no = was_no
|
||||
|
|
@ -45,23 +40,22 @@ function el_kind(ui_st: mut UiState, n: UiNode, tag: string) -> void {
|
|||
} else if tag == "input" or tag == "select" { n.focusable = true } else if tag == "spacer" { n.kind = UI_SPACER } else if tag == "scroll" { n.kind = UI_SCROLL } else if tag == "img" { n.kind = UI_IMAGE } else if tag == "hr" { n.kind = UI_RULE } else if not lk_in(EL_BOXES, tag) { ui_err(ui_st, `<{tag}>: there is no such element`) }
|
||||
}
|
||||
# a box with words in it holds them as a text of its own, as <div>words</div> does
|
||||
function el_text(n: UiNode, s: string) -> void {
|
||||
function el_text(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
||||
if n.kind != UI_BOX and n.kind != UI_SCROLL {
|
||||
n.text = s
|
||||
return
|
||||
}
|
||||
let t = new UiNode
|
||||
let t = nd_take(ui_st)
|
||||
t.kind = UI_TEXT
|
||||
t.text = s
|
||||
t.env = n.env
|
||||
t.children = new []UiNode
|
||||
push(n.children, t)
|
||||
}
|
||||
# id, class, hidden, disabled and src say what the element is; the rest are applied after the rules
|
||||
function el_keep(n: UiNode, key: string, v: Val) -> void {
|
||||
let s = vl_text(v)
|
||||
function el_keep(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> void {
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "id" { n.id = s } else if key == "class" {
|
||||
let parts = lss_split(s, 32)
|
||||
let parts = mm_split(ui_st, s, 32)
|
||||
for i in 0 .. len(parts) {
|
||||
if len(parts[i]) > 0 { push(n.classes, parts[i]) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,8 @@ export property UiEnv {
|
|||
inst: UiInst = null # the Ludic component whose template this is
|
||||
}
|
||||
|
||||
function env_new(parent: UiEnv) -> UiEnv {
|
||||
let e = new UiEnv
|
||||
e.names = new []string
|
||||
e.vals = new []Val
|
||||
function env_new(ui_st: mut UiState, parent: UiEnv) -> UiEnv {
|
||||
let e = env_take(ui_st)
|
||||
e.parent = parent
|
||||
if parent != null {
|
||||
e.model = parent.model
|
||||
|
|
@ -84,7 +82,7 @@ export function ui_err(ui_st: mut UiState, msg0: string) -> void {
|
|||
function ui_has(s: string, part: string) -> bool {
|
||||
let n = len(part)
|
||||
for i in 0 .. len(s) - n + 1 {
|
||||
if s[i..i + n] == part { return true }
|
||||
if sat(s, i, part) { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,18 @@ function ui_eval(ui_st: mut UiState, x: UiExpr, e: UiEnv) -> Val {
|
|||
}
|
||||
# a call: len() and range() are the template's own, anything else is the view's
|
||||
function ev_call(ui_st: mut UiState, x: UiExpr, e: UiEnv) -> Val {
|
||||
let args = Value.list()
|
||||
let depth = ui_st.ev_depth
|
||||
while len(ui_st.ev_args) <= depth { push(ui_st.ev_args, Value.list()) }
|
||||
let args = ui_st.ev_args[depth]
|
||||
Value.clear(args)
|
||||
ui_st.ev_depth = depth + 1
|
||||
for i in 0 .. len(x.args) { Value.add(args, ui_eval(ui_st, x.args[i], e)) }
|
||||
let r = ev_call_with(ui_st, x, e, args)
|
||||
ui_st.ev_depth = depth
|
||||
return r
|
||||
}
|
||||
# the call itself, its arguments evaluated; a callee reads them and keeps none
|
||||
function ev_call_with(ui_st: mut UiState, x: UiExpr, e: UiEnv, args: Val) -> Val {
|
||||
if x.s == "len" and len(x.args) == 1 { return Value.int(Value.count(Value.at(args, 0))) }
|
||||
if x.s == "range" and len(x.args) == 1 {
|
||||
let out = Value.list()
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ function rd_op(r: UiRd, op: string) -> bool {
|
|||
rd_ws(r)
|
||||
let n = len(op)
|
||||
if r.i + n > len(r.s) { return false }
|
||||
if r.s[r.i..r.i + n] != op { return false }
|
||||
if not sat(r.s, r.i, op) { return false }
|
||||
r.i += n
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,23 +39,19 @@ export function ui_nodes(ui_st: mut UiState, screen: string, view: UiView) -> Ui
|
|||
return null
|
||||
}
|
||||
let t = ui_st.lib_screens[si]
|
||||
pl_begin(ui_st, screen)
|
||||
lc_begin(ui_st)
|
||||
ui_st.ui_view = view
|
||||
let e = env_new(null)
|
||||
let e = env_new(ui_st, null)
|
||||
if view != null and view.model != null { e.model = view.model() } else { e.model = Value.object() }
|
||||
e.state = st_for(ui_st, screen, t, e)
|
||||
let root = new UiNode
|
||||
let root = nd_take(ui_st)
|
||||
root.key = screen
|
||||
root.children = new []UiNode
|
||||
root.env = e
|
||||
root.sheet = t.sheet
|
||||
root.classes = new []string
|
||||
root.akeys = new []string
|
||||
root.avals = new []string
|
||||
root.vals = new []Val
|
||||
root.tag = "screen"
|
||||
for i in 0 .. len(t.keys) {
|
||||
if t.keys[i] != "name" { el_keep(root, t.keys[i], ui_eval(ui_st, t.vals[i], e)) }
|
||||
if t.keys[i] != "name" { el_keep(ui_st, root, t.keys[i], ui_eval(ui_st, t.vals[i], e)) }
|
||||
}
|
||||
bd_kids(ui_st, t.kids, e, screen, root.children)
|
||||
cs_tree(ui_st, root)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ import "node.ludic"
|
|||
import "node_more.ludic"
|
||||
import "view.ludic"
|
||||
import "backend.ludic"
|
||||
import "pool.ludic"
|
||||
import "pool_reset.ludic"
|
||||
import "pool_reset_more.ludic"
|
||||
import "memo.ludic"
|
||||
import "memo_join.ludic"
|
||||
import "expr.ludic"
|
||||
import "expr_parse.ludic"
|
||||
import "expr_prim.ludic"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ property UiInst {
|
|||
cls: UiClass = null
|
||||
ptr: pointer = null
|
||||
seen: int = 0
|
||||
props: Val = null # its props, filled again each frame into the same object
|
||||
}
|
||||
function in_get(ui_st: mut UiState, key: string, k: UiClass) -> UiInst {
|
||||
for i in 0 .. len(ui_st.in_list) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@ function ly_place_line(ui_st: mut UiState, n: UiNode, from: int, to: int, top: f
|
|||
var used = 0.0
|
||||
var grows = 0.0
|
||||
var count = 0
|
||||
let sizes = new []float
|
||||
let depth = ui_st.ly_depth
|
||||
ui_st.ly_depth += 1
|
||||
let sizes = ly_scratch(ui_st, depth)
|
||||
for i in from .. to {
|
||||
push(sizes, ly_basis(n.children[i], n.dir, main_room))
|
||||
if n.children[i].pos < 2 {
|
||||
|
|
@ -52,7 +54,7 @@ function ly_place_line(ui_st: mut UiState, n: UiNode, from: int, to: int, top: f
|
|||
}
|
||||
used = used + n.gap * float(Math.max(count - 1, 0))
|
||||
let free = main_room - used
|
||||
if free < 0.0 { ly_shrink_line(n, from, sizes, 0.0 - free) }
|
||||
if free < 0.0 { ly_shrink_line(ui_st, depth, n, from, sizes, 0.0 - free) }
|
||||
ly_justify(ui_st, n, free, count, grows)
|
||||
let extra = ui_st.ly_extra
|
||||
var at = ui_st.ly_lead
|
||||
|
|
@ -65,6 +67,17 @@ function ly_place_line(ui_st: mut UiState, n: UiNode, from: int, to: int, top: f
|
|||
if c.pos == 1 { ly_nudge(n, c) }
|
||||
at = at + m + n.gap + extra
|
||||
}
|
||||
ui_st.ly_depth = depth
|
||||
}
|
||||
# a line's sizes, and its shrink's frozen flags, in lists kept one a depth (a line's children lay out
|
||||
# their own lines while it is still placing them), emptied rather than made anew
|
||||
function ly_scratch(ui_st: mut UiState, depth: int) -> []float {
|
||||
while len(ui_st.ly_sizes) <= depth {
|
||||
push(ui_st.ly_sizes, new []float)
|
||||
push(ui_st.ly_frozen, new []bool)
|
||||
}
|
||||
List.clear(ui_st.ly_sizes[depth])
|
||||
return ui_st.ly_sizes[depth]
|
||||
}
|
||||
# one child: `m` along the run and its own size (or the whole room, stretched) across, less margins
|
||||
function ly_place_child(ui_st: mut UiState, n: UiNode, c: UiNode, at: float, top: float, m: float, cross_room: float) -> void {
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ function ly_min_h(c: UiNode) -> float {
|
|||
return c.mh
|
||||
}
|
||||
# `sizes` (the children from..to) shrunk by `over` in all
|
||||
function ly_shrink_line(n: UiNode, from: int, sizes: []float, over0: float) -> void {
|
||||
function ly_shrink_line(ui_st: mut UiState, depth: int, n: UiNode, from: int, sizes: []float, over0: float) -> void {
|
||||
var over = over0
|
||||
let frozen = new []bool
|
||||
let frozen = ui_st.ly_frozen[depth]
|
||||
List.clear(frozen)
|
||||
for k in 0 .. len(sizes) { push(frozen, n.children[from + k].pos >= 2) }
|
||||
for pass in 0 .. 8 {
|
||||
var wsum = 0.0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# layout_text.ludic - a text's size: one line, or as many as it takes to fit its room (white-space
|
||||
# normal), breaking between words; nowrap keeps one line, and text-overflow: ellipsis cuts it
|
||||
function ly_measure_text(ui_st: UiState, n: UiNode, avail: float) -> void {
|
||||
function ly_measure_text(ui_st: mut UiState, n: UiNode, avail: float) -> void {
|
||||
n.lines = null
|
||||
let lh = ly_line_h(n)
|
||||
var one = ly_text_w(ui_st, n.text, n.rsize)
|
||||
|
|
@ -19,8 +19,8 @@ function ly_measure_text(ui_st: UiState, n: UiNode, avail: float) -> void {
|
|||
n.mw = n.mw + widest
|
||||
n.mh = n.mh + lh * float(len(n.lines))
|
||||
}
|
||||
function ly_wrap(ui_st: UiState, s: string, size: float, room: float) -> []string {
|
||||
let words = lss_split(s, 32)
|
||||
function ly_wrap(ui_st: mut UiState, s: string, size: float, room: float) -> []string {
|
||||
let words = mm_split(ui_st, s, 32)
|
||||
let out = new []string
|
||||
var line = ""
|
||||
for i in 0 .. len(words) {
|
||||
|
|
|
|||
|
|
@ -39,3 +39,13 @@ function lib_beside(path: string, src: string) -> string {
|
|||
if cut < 0 { return src }
|
||||
return path[0..cut + 1] + src
|
||||
}
|
||||
# `s` has `p` starting at `at`: compared in place, where s[at..at + len(p)] == p made a new string
|
||||
# for every place it looked (Ludic frees nothing, and the cascade asks this per element per frame)
|
||||
function sat(s: string, at: int, p: string) -> bool {
|
||||
let n = len(p)
|
||||
if at < 0 or at + n > len(s) { return false }
|
||||
for i in 0 .. n {
|
||||
if s[at + i] != p[i] { return false }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ function lc_note(ui_st: mut UiState, key: string, names: []string, acts: []UiAct
|
|||
}
|
||||
function lc_mine(key: string, screen: string) -> bool {
|
||||
let n = len(screen)
|
||||
return key == screen or (len(key) > n and key[0..n] == screen and key[n] == 47)
|
||||
return key == screen or (len(key) > n and sat(key, 0, screen) and key[n] == 47)
|
||||
}
|
||||
# the screen's mounts and unmounts since its last frame; other screens' records are kept
|
||||
function lc_run(ui_st: mut UiState, screen: string) -> void {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,9 @@ function lk_kids(ui_st: mut UiState, f: UiFile, t: UiTpl) -> void {
|
|||
function lk_element(ui_st: UiState, tag: string) -> bool { return lk_in(LK_OWN, tag) or lk_in(EL_BOXES, tag) or lk_in(EL_TEXTS, tag) or nt_find(ui_st, tag) != null }
|
||||
# a word in a list of words written " a b c "
|
||||
function lk_in(words: string, w: string) -> bool {
|
||||
let pat = ` {w} `
|
||||
let n = len(pat)
|
||||
for i in 0 .. len(words) - n + 1 {
|
||||
if words[i..i + n] == pat { return true }
|
||||
let n = len(w)
|
||||
for i in 0 .. len(words) - n - 1 {
|
||||
if words[i] == 32 and words[i + n + 1] == 32 and sat(words, i + 1, w) { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
68
packages/ludic.ui/memo.ludic
Normal file
68
packages/ludic.ui/memo.ludic
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# memo.ludic - what a frame would work out again from the same text is kept by that text: a value
|
||||
# split into its words, a gradient, a key joined from its parent's. Ludic frees nothing, so parsing
|
||||
# "2px 6px" per element per frame was a leak; the table is bounded, and past it a result is made
|
||||
# (and lost) as before rather than the table growing without end.
|
||||
const MM_CAP: int = 8192 # slots; at most three quarters are used
|
||||
export property UiMemo {
|
||||
slots: words = null # index + 1 into keys, 0 empty
|
||||
keys: []string = null # the text a result was made from (or the joined text itself)
|
||||
tags: []int = null # what kind of result: a separator, or a kind below
|
||||
lists: [][]string = null
|
||||
grads: []UiGradient = null
|
||||
}
|
||||
const MM_WORDS: int = -1 # el_words: spaces, a bracket's own kept
|
||||
const MM_GRAD: int = -2
|
||||
const MM_JOIN: int = -3 # keys[i] is the joined text itself
|
||||
function mm_new() -> UiMemo {
|
||||
let m = new UiMemo
|
||||
m.slots = words(MM_CAP)
|
||||
m.keys = new []string
|
||||
m.tags = new []int
|
||||
m.lists = new [][]string
|
||||
m.grads = new []UiGradient
|
||||
return m
|
||||
}
|
||||
function mm_of(ui_st: mut UiState) -> UiMemo {
|
||||
if ui_st.mm == null { ui_st.mm = mm_new() }
|
||||
return ui_st.mm
|
||||
}
|
||||
# FNV-1a over the text, the tag mixed in first
|
||||
function mm_hash(tag: int, s: string) -> int {
|
||||
var h = 216613626 ^ (tag & 255)
|
||||
for i in 0 .. len(s) { h = ((h ^ s[i]) * 16777619) & 2147483647 }
|
||||
return h
|
||||
}
|
||||
# the entry for (tag, s), or -1
|
||||
function mm_find(m: UiMemo, tag: int, s: string) -> int {
|
||||
var at = mm_hash(tag, s) & (MM_CAP - 1)
|
||||
while m.slots[at] != 0 {
|
||||
let i = m.slots[at] - 1
|
||||
if m.tags[i] == tag and m.keys[i] == s { return i }
|
||||
at = (at + 1) & (MM_CAP - 1)
|
||||
}
|
||||
return -1
|
||||
}
|
||||
# a new entry for (tag, s) with its results empty, or -1 when the table is full
|
||||
function mm_add(m: UiMemo, tag: int, s: string) -> int {
|
||||
if len(m.keys) * 4 >= MM_CAP * 3 { return -1 }
|
||||
var at = mm_hash(tag, s) & (MM_CAP - 1)
|
||||
while m.slots[at] != 0 { at = (at + 1) & (MM_CAP - 1) }
|
||||
push(m.keys, s)
|
||||
push(m.tags, tag)
|
||||
push(m.lists, null)
|
||||
push(m.grads, null)
|
||||
m.slots[at] = len(m.keys)
|
||||
return len(m.keys) - 1
|
||||
}
|
||||
# lss_split's parts of `s` at `c`, made once per text; the list is shared - read it, never change it
|
||||
function mm_split(ui_st: mut UiState, s: string, c: int) -> []string {
|
||||
let m = mm_of(ui_st)
|
||||
let i = mm_find(m, c, s)
|
||||
if i >= 0 { return m.lists[i] }
|
||||
var parts: []string = null
|
||||
if c == MM_WORDS { parts = el_words(s) } else { parts = lss_split(s, c) }
|
||||
let j = mm_add(m, c, s)
|
||||
if j >= 0 { m.lists[j] = parts }
|
||||
return parts
|
||||
}
|
||||
function mm_words(ui_st: mut UiState, s: string) -> []string { return mm_split(ui_st, s, MM_WORDS) }
|
||||
51
packages/ludic.ui/memo_join.ludic
Normal file
51
packages/ludic.ui/memo_join.ludic
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# memo_join.ludic - a key joined from its parent's key, a separator and a part ("App/3",
|
||||
# "App/3#7", "App/3/ui-thumb"), found by comparing in place, so an element's key is made once
|
||||
# the element first appears and never again
|
||||
function mm_hash_join(a: string, sep: string, b: string) -> int {
|
||||
var h = 216613626 ^ (MM_JOIN & 255)
|
||||
for i in 0 .. len(a) { h = ((h ^ a[i]) * 16777619) & 2147483647 }
|
||||
h = ((h ^ sep[0]) * 16777619) & 2147483647
|
||||
for i in 0 .. len(b) { h = ((h ^ b[i]) * 16777619) & 2147483647 }
|
||||
return h
|
||||
}
|
||||
function mm_is_join(k: string, a: string, sep: string, b: string) -> bool {
|
||||
let na = len(a)
|
||||
if len(k) != na + 1 + len(b) or k[na] != sep[0] { return false }
|
||||
return sat(k, 0, a) and sat(k, na + 1, b)
|
||||
}
|
||||
# a + sep + b, the same string every frame
|
||||
function mm_join(ui_st: mut UiState, a: string, sep: string, b: string) -> string {
|
||||
let m = mm_of(ui_st)
|
||||
var at = mm_hash_join(a, sep, b) & (MM_CAP - 1)
|
||||
while m.slots[at] != 0 {
|
||||
let i = m.slots[at] - 1
|
||||
if m.tags[i] == MM_JOIN and mm_is_join(m.keys[i], a, sep, b) { return m.keys[i] }
|
||||
at = (at + 1) & (MM_CAP - 1)
|
||||
}
|
||||
let k = a + sep + b
|
||||
if len(m.keys) * 4 >= MM_CAP * 3 { return k }
|
||||
push(m.keys, k)
|
||||
push(m.tags, MM_JOIN)
|
||||
push(m.lists, null)
|
||||
push(m.grads, null)
|
||||
m.slots[at] = len(m.keys)
|
||||
return k
|
||||
}
|
||||
# a small whole number's text, made once (a key's index, a loop's count)
|
||||
function mm_int(ui_st: mut UiState, i: int) -> string {
|
||||
if i < 0 or i >= 1024 { return string(i) }
|
||||
if ui_st.mm_ints == null {
|
||||
ui_st.mm_ints = new []string
|
||||
for k in 0 .. 1024 { push(ui_st.mm_ints, string(k)) }
|
||||
}
|
||||
return ui_st.mm_ints[i]
|
||||
}
|
||||
# a small whole number as a Value, made once and shared: read it, never change it (a loop's index)
|
||||
function mm_ival(ui_st: mut UiState, i: int) -> Val {
|
||||
if i < 0 or i >= 1024 { return Value.int(i) }
|
||||
if ui_st.mm_ivals == null {
|
||||
ui_st.mm_ivals = new []Val
|
||||
for k in 0 .. 1024 { push(ui_st.mm_ivals, Value.int(k)) }
|
||||
}
|
||||
return ui_st.mm_ivals[i]
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ function nt_run(ui_st: mut UiState, n: UiNode, name: string, value: Val) -> void
|
|||
if (lk_in(PE_NAMES, name) or name == "hold") and Value.kind(value) == 6 { ev = value }
|
||||
Value.put(ev, "name", Value.str(name))
|
||||
Value.put(ev, "value", value)
|
||||
let e = env_new(n.env)
|
||||
let e = env_new(ui_st, n.env)
|
||||
env_bind(e, "event", ev)
|
||||
act_run(ui_st, n.on_acts[i], e)
|
||||
}
|
||||
|
|
@ -78,7 +78,13 @@ export function ui_attr(n: UiNode, key: string) -> Val {
|
|||
}
|
||||
return Value.null()
|
||||
}
|
||||
export function ui_attr_text(n: UiNode, key: string) -> string { return vl_text(ui_attr(n, key)) }
|
||||
export function ui_attr_text(n: UiNode, key: string) -> string {
|
||||
if n.akeys == null { return "" }
|
||||
for i in 0 .. len(n.akeys) {
|
||||
if n.akeys[i] == key { return vl_text(n.vals[i]) }
|
||||
}
|
||||
return ""
|
||||
}
|
||||
# a boolean attribute: present with no value is true, as HTML's are (<button autofocus>)
|
||||
export function ui_attr_on(n: UiNode, key: string) -> bool {
|
||||
if n.akeys == null { return false }
|
||||
|
|
|
|||
84
packages/ludic.ui/pool.ludic
Normal file
84
packages/ludic.ui/pool.ludic
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# pool.ludic - what a frame is built of is kept and used again: ludic.ui builds a screen's tree anew
|
||||
# every frame, and Ludic frees nothing, so a node or an env made per element per frame was a leak
|
||||
# (the valley's HUD: ~100 MB/s). Each screen keeps two generations and alternates, so last frame's
|
||||
# tree - which an unmount's env, a hover or ui_box still reads - stays whole while this one is built.
|
||||
# So a host may read a tree until the same screen has been built twice more, and never keep it longer.
|
||||
export property UiPool {
|
||||
key: string = ""
|
||||
gen: int = 0
|
||||
nodes0: []UiNode = null
|
||||
nodes1: []UiNode = null
|
||||
envs0: []UiEnv = null
|
||||
envs1: []UiEnv = null
|
||||
un: int = 0
|
||||
ue: int = 0
|
||||
}
|
||||
# a build of `screen` begins: its other generation is handed out again from the start
|
||||
function pl_begin(ui_st: mut UiState, screen: string) -> void {
|
||||
var p: UiPool = null
|
||||
for i in 0 .. len(ui_st.pl_pools) {
|
||||
if ui_st.pl_pools[i].key == screen { p = ui_st.pl_pools[i] }
|
||||
}
|
||||
if p == null {
|
||||
p = new UiPool
|
||||
p.key = screen
|
||||
p.nodes0 = new []UiNode
|
||||
p.nodes1 = new []UiNode
|
||||
p.envs0 = new []UiEnv
|
||||
p.envs1 = new []UiEnv
|
||||
push(ui_st.pl_pools, p)
|
||||
}
|
||||
p.gen = 1 - p.gen
|
||||
p.un = 0
|
||||
p.ue = 0
|
||||
ui_st.pl_cur = p
|
||||
}
|
||||
# a node, blank, with its own lists (empty) - from the pool when a build is under way
|
||||
function nd_take(ui_st: mut UiState) -> UiNode {
|
||||
let p = ui_st.pl_cur
|
||||
if p == null { return nd_fresh() }
|
||||
var list = p.nodes0
|
||||
if p.gen == 1 { list = p.nodes1 }
|
||||
if p.un < len(list) {
|
||||
let n = list[p.un]
|
||||
p.un += 1
|
||||
nd_reset(n)
|
||||
return n
|
||||
}
|
||||
let n = nd_fresh()
|
||||
push(list, n)
|
||||
p.un += 1
|
||||
return n
|
||||
}
|
||||
function nd_fresh() -> UiNode {
|
||||
let n = new UiNode
|
||||
n.children = new []UiNode
|
||||
n.classes = new []string
|
||||
n.akeys = new []string
|
||||
n.avals = new []string
|
||||
n.vals = new []Val
|
||||
return n
|
||||
}
|
||||
function env_take(ui_st: mut UiState) -> UiEnv {
|
||||
let p = ui_st.pl_cur
|
||||
if p == null { return env_fresh() }
|
||||
var list = p.envs0
|
||||
if p.gen == 1 { list = p.envs1 }
|
||||
if p.ue < len(list) {
|
||||
let e = list[p.ue]
|
||||
p.ue += 1
|
||||
env_reset(e)
|
||||
return e
|
||||
}
|
||||
let e = env_fresh()
|
||||
push(list, e)
|
||||
p.ue += 1
|
||||
return e
|
||||
}
|
||||
function env_fresh() -> UiEnv {
|
||||
let e = new UiEnv
|
||||
e.names = new []string
|
||||
e.vals = new []Val
|
||||
e.on_envs = new []UiEnv
|
||||
return e
|
||||
}
|
||||
61
packages/ludic.ui/pool_reset.ludic
Normal file
61
packages/ludic.ui/pool_reset.ludic
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# pool_reset.ludic - a pooled node put back to its defaults: every field, and the lists it owns
|
||||
# emptied and kept (generated from node.ludic - a field added there is added here)
|
||||
function nd_reset(n: UiNode) -> void {
|
||||
nd_reset_a(n)
|
||||
nd_reset_b(n)
|
||||
}
|
||||
function nd_reset_a(n: UiNode) -> void {
|
||||
n.kind = 0
|
||||
n.dir = 0
|
||||
n.text = ""
|
||||
n.key = ""
|
||||
n.tag = ""
|
||||
n.id = ""
|
||||
if n.classes != null { List.clear(n.classes) }
|
||||
if n.akeys != null { List.clear(n.akeys) }
|
||||
if n.avals != null { List.clear(n.avals) }
|
||||
if n.vals != null { List.clear(n.vals) }
|
||||
n.style = null
|
||||
n.sheet = null
|
||||
if n.ups != null { List.clear(n.ups) }
|
||||
n.parent = null
|
||||
n.index = 0
|
||||
n.src = ""
|
||||
n.size = 0.0
|
||||
n.w = -1000000.0
|
||||
n.h = -1000000.0
|
||||
n.w_pct = 0.0
|
||||
n.h_pct = 0.0
|
||||
n.pt = 0.0
|
||||
n.pr = 0.0
|
||||
n.pb = 0.0
|
||||
n.pl = 0.0
|
||||
n.mt = 0.0
|
||||
n.mr = 0.0
|
||||
n.mb = 0.0
|
||||
n.ml = 0.0
|
||||
n.border = 0.0
|
||||
n.bt = 0.0
|
||||
n.br = 0.0
|
||||
n.bb = 0.0
|
||||
n.bl = 0.0
|
||||
n.border_c = -2
|
||||
n.gap = 0.0
|
||||
n.align = 0
|
||||
n.justify = 0
|
||||
n.talign = 0
|
||||
n.self = -1
|
||||
n.grow = 0.0
|
||||
n.wrap = false
|
||||
n.min_w = 0.0
|
||||
n.max_w = 0.0
|
||||
n.min_h = 0.0
|
||||
n.max_h = 0.0
|
||||
n.hidden = false
|
||||
n.pos = 0
|
||||
n.top = -1000000.0
|
||||
n.right = -1000000.0
|
||||
n.bottom = -1000000.0
|
||||
n.left = -1000000.0
|
||||
n.z = 0
|
||||
}
|
||||
96
packages/ludic.ui/pool_reset_more.ludic
Normal file
96
packages/ludic.ui/pool_reset_more.ludic
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# pool_reset_more.ludic - the rest of a pooled node's fields, its extras and an env, to their defaults
|
||||
function nd_reset_b(n: UiNode) -> void {
|
||||
n.nowrap = false
|
||||
n.ellipsis = false
|
||||
if n.lines != null { List.clear(n.lines) }
|
||||
if n.var_names != null { List.clear(n.var_names) }
|
||||
if n.var_vals != null { List.clear(n.var_vals) }
|
||||
n.fg = -1
|
||||
n.fg_a = 1.0
|
||||
n.bg = -2
|
||||
n.bg_a = 1.0
|
||||
n.border_a = 1.0
|
||||
n.rfg_a = 1.0
|
||||
n.alpha = 1.0
|
||||
n.enabled = true
|
||||
n.act = null
|
||||
n.on_names = null
|
||||
n.on_acts = null
|
||||
n.native = null
|
||||
n.env = null
|
||||
if n.children != null { List.clear(n.children) }
|
||||
n.mw = 0.0
|
||||
n.mh = 0.0
|
||||
n.content_h = 0.0
|
||||
n.x = 0.0
|
||||
n.y = 0.0
|
||||
n.cw = 0.0
|
||||
n.ch = 0.0
|
||||
n.rsize = 0.0
|
||||
n.rfg = 0
|
||||
n.hovered = false
|
||||
n.focusable = false
|
||||
n.radius = 0.0
|
||||
n.outline_w = 0.0
|
||||
n.outline_c = -1
|
||||
n.outline_a = 1.0
|
||||
n.outline_off = 0.0
|
||||
n.scroll_y = 0.0
|
||||
n.bar_c = -1
|
||||
n.bar_track = -2
|
||||
n.opts = null
|
||||
n.bg_img = ""
|
||||
n.bi_src = ""
|
||||
n.bi_slice = 0.0
|
||||
n.bi_width = 0.0
|
||||
n.sh_x = 0.0
|
||||
n.sh_y = 0.0
|
||||
n.sh_c = -2
|
||||
n.sh_a = 1.0
|
||||
n.anim = ""
|
||||
n.anim_dur = 0.0
|
||||
n.anim_loop = false
|
||||
n.anim_alt = false
|
||||
n.tr_dur = 0.0
|
||||
n.popover = false
|
||||
if n.ex != null { nx_reset(n.ex) }
|
||||
}
|
||||
function nx_reset(x: UiNodeX) -> void {
|
||||
x.shrink = -1.0
|
||||
x.order = 0
|
||||
x.w_off = 0.0
|
||||
x.h_off = 0.0
|
||||
x.mh_min = 0.0
|
||||
x.has_min = false
|
||||
x.tsh_set = false
|
||||
x.tsh_x = 0.0
|
||||
x.tsh_y = 0.0
|
||||
x.tsh_c = -2
|
||||
x.tsh_a = 1.0
|
||||
x.no_pointer = false
|
||||
x.fit_min = 0.0
|
||||
x.lh_kind = 0
|
||||
x.lh_v = 0.0
|
||||
x.ip_t = 0.0
|
||||
x.ip_r = 0.0
|
||||
x.ip_b = 0.0
|
||||
x.ip_l = 0.0
|
||||
x.grad = null
|
||||
x.ratio = 0.0
|
||||
x.fit_obj = 0
|
||||
x.zoom = 1.0
|
||||
}
|
||||
function env_reset(e: UiEnv) -> void {
|
||||
if e.names != null { List.clear(e.names) }
|
||||
if e.vals != null { List.clear(e.vals) }
|
||||
e.state = null
|
||||
e.parent = null
|
||||
e.model = null
|
||||
e.slot = null
|
||||
e.slot_env = null
|
||||
e.on_names = null
|
||||
e.on_acts = null
|
||||
if e.on_envs != null { List.clear(e.on_envs) }
|
||||
e.ctx = null
|
||||
e.inst = null
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ function r3u_image_h(render3d_st: mut Render3dState, ui_st: mut UiState, src: st
|
|||
function r3u_is_cell(ui_st: UiState, src: string) -> bool {
|
||||
for k in 0 .. len(ui_st.r3u_atlas) {
|
||||
let p = ui_st.r3u_atlas[k]
|
||||
if len(src) > len(p) and src[0..len(p)] == p and src[len(p)] == 58 { return true }
|
||||
if len(src) > len(p) and sat(src, 0, p) and src[len(p)] == 58 { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
# screen_class.ludic - a Ludic component shown as a whole screen
|
||||
# a Ludic component shown as a screen: an instance at the top, keyed by its name
|
||||
function fr_class_nodes(ui_st: mut UiState, cls: UiClass) -> UiNode {
|
||||
pl_begin(ui_st, cls.name)
|
||||
lc_begin(ui_st)
|
||||
ui_st.in_build += 1
|
||||
ui_st.ui_view = null
|
||||
uc_load(ui_st, cls)
|
||||
let root = fr_root(cls.name, cls.sheet)
|
||||
let root = fr_root(ui_st, cls.name, cls.sheet)
|
||||
let use = new UiTpl
|
||||
use.tag = cls.name
|
||||
use.cls = cls
|
||||
|
|
@ -14,7 +15,7 @@ function fr_class_nodes(ui_st: mut UiState, cls: UiClass) -> UiNode {
|
|||
use.on_keys = new []string
|
||||
use.on_acts = new []UiAct
|
||||
use.kids = new []UiTpl
|
||||
let e = env_new(null)
|
||||
let e = env_new(ui_st, null)
|
||||
e.model = Value.object()
|
||||
root.env = e
|
||||
bd_class(ui_st, use, e, cls.name, root.children)
|
||||
|
|
@ -22,15 +23,10 @@ function fr_class_nodes(ui_st: mut UiState, cls: UiClass) -> UiNode {
|
|||
cs_tree(ui_st, root)
|
||||
return root
|
||||
}
|
||||
function fr_root(key: string, sheet: UiSheet) -> UiNode {
|
||||
let root = new UiNode
|
||||
function fr_root(ui_st: mut UiState, key: string, sheet: UiSheet) -> UiNode {
|
||||
let root = nd_take(ui_st)
|
||||
root.key = key
|
||||
root.tag = "screen"
|
||||
root.sheet = sheet
|
||||
root.children = new []UiNode
|
||||
root.classes = new []string
|
||||
root.akeys = new []string
|
||||
root.avals = new []string
|
||||
root.vals = new []Val
|
||||
return root
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
# it where it was taken; a press on the track jumps the thumb's middle to the pointer and holds it there.
|
||||
# the bar's parts, styled as descendants of the box, and where they are at this offset
|
||||
function sb_geo(ui_st: mut UiState, n: UiNode, off: float, room: float, most: float) -> void {
|
||||
let bar = ct_part(n, "ui-scrollbar", "")
|
||||
let bar = ct_part(ui_st, n, "ui-scrollbar", "")
|
||||
bar.tag = "div"
|
||||
bar.parent = n
|
||||
push(bar.children, ct_part(n, "ui-thumb", ""))
|
||||
push(bar.children, ct_part(ui_st, n, "ui-thumb", ""))
|
||||
cs_tree(ui_st, bar)
|
||||
ui_st.sb_bar = bar
|
||||
ui_st.sb_w = ui_px(ui_st, 6.0)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export function ui_forget(ui_st: mut UiState, screen: string) -> void {
|
|||
let vals = new []Val
|
||||
for i in 0 .. len(ui_st.st_keys) {
|
||||
let k = ui_st.st_keys[i]
|
||||
let mine = len(k) >= len(screen) and k[0..len(screen)] == screen and (len(k) == len(screen) or k[len(screen)] == 47)
|
||||
let mine = len(k) >= len(screen) and sat(k, 0, screen) and (len(k) == len(screen) or k[len(screen)] == 47)
|
||||
if not mine {
|
||||
push(keys, k)
|
||||
push(vals, ui_st.st_vals[i])
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ function sheet_read(ui_st: mut UiState, f: UiFile, t: UiTpl) -> void {
|
|||
if from != "" { src = lib_text(ui_st, lib_beside(f.path, from)) }
|
||||
lss_text(ui_st, f, src)
|
||||
}
|
||||
function lss_is(path: string) -> bool { return len(path) > 4 and path[len(path) - 4..len(path)] == ".lss" }
|
||||
function lss_is(path: string) -> bool { return len(path) > 4 and sat(path, len(path) - 4, ".lss") }
|
||||
# a stylesheet file: a file with rules and imports and nothing else
|
||||
function lss_file(ui_st: mut UiState, src: string, path: string) -> UiFile {
|
||||
let f = lib_new(ui_st, path)
|
||||
|
|
@ -64,7 +64,7 @@ function lss_block(ui_st: mut UiState, f: UiFile, src: string, md: UiMedia, err:
|
|||
# @import "base.lss"; - its rules come before this file's own
|
||||
function lss_import(ui_st: mut UiState, f: UiFile, what: string) -> void {
|
||||
var p = tpl_words(what)
|
||||
if len(p) > 5 and p[0..4] == "url(" { p = p[4..len(p) - 1] }
|
||||
if len(p) > 5 and sat(p, 0, "url(") { p = p[4..len(p) - 1] }
|
||||
if len(p) >= 2 and (p[0] == 34 or p[0] == 39) { p = p[1..len(p) - 1] }
|
||||
let other = lib_file(ui_st, lib_beside(f.path, p))
|
||||
if other != null {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# text_fit.ludic - text-fit: shrink 12px draws a line that does not fit its box smaller, down to that
|
||||
# size, and cuts what still does not fit with an ellipsis; line-height (a multiple of the font size,
|
||||
# px or em) spaces a text's lines. Both are inherited, as font properties are.
|
||||
function el_text_fit(ui_st: UiState, n: UiNode, s: string) -> void {
|
||||
let parts = lss_split(tpl_words(s), 32)
|
||||
function el_text_fit(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
||||
let parts = mm_split(ui_st, tpl_words(s), 32)
|
||||
nx(n).fit_min = 0.0
|
||||
if len(parts) >= 2 and parts[0] == "shrink" { nx(n).fit_min = Math.max(el_unit(ui_st, parts[1]), 1.0) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,11 @@ function tt_under(n: UiNode, x: float, y: float) -> UiNode {
|
|||
}
|
||||
function tt_draw(ui_st: mut UiState, root: UiNode) -> void {
|
||||
if ui_st.tt_key == "" or ui_st.tt_text == "" or an_now(ui_st) - ui_st.tt_since < 0.5 { return }
|
||||
let n = ct_part(root, "ui-tooltip", "")
|
||||
let n = ct_part(ui_st, root, "ui-tooltip", "")
|
||||
n.tag = "div"
|
||||
n.parent = root
|
||||
n.children = new []UiNode
|
||||
let lines = tt_lines(ui_st.tt_text)
|
||||
for i in 0 .. len(lines) { push(n.children, ct_part(root, "ui-tooltip-text", lines[i])) }
|
||||
for i in 0 .. len(lines) { push(n.children, ct_part(ui_st, root, "ui-tooltip-text", lines[i])) }
|
||||
cs_tree(ui_st, n)
|
||||
ly_measure(ui_st, n, ui_st.ly_vp_w * 0.4, ui_px(ui_st, 16.0), root.rfg)
|
||||
let x = Math.min(ui_st.tt_x + ui_px(ui_st, 16.0), ui_st.ly_vp_x + ui_st.ly_vp_w - n.mw)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ function tpl_read(ui_st: mut UiState, x: Xml, file: string) -> UiTpl {
|
|||
for i in 0 .. len(x.akeys) {
|
||||
let k: string = x.akeys[i]
|
||||
let v: string = x.avals[i]
|
||||
if len(k) > 3 and k[0..3] == "on-" {
|
||||
if len(k) > 3 and sat(k, 0, "on-") {
|
||||
push(t.on_keys, tpl_event(k[3..len(k)]))
|
||||
push(t.on_acts, act_parse(v, err))
|
||||
} else if k == "onclick" {
|
||||
|
|
@ -68,6 +68,7 @@ function tpl_value(v: string, err: []string) -> UiExpr {
|
|||
}
|
||||
# text as a reader sees it: the ends trimmed and every run of white space one space
|
||||
function tpl_words(s: string) -> string {
|
||||
if tpl_clean(s) { return s }
|
||||
var out = ""
|
||||
var gap = false
|
||||
for i in 0 .. len(s) {
|
||||
|
|
@ -86,3 +87,15 @@ function tpl_attr(t: UiTpl, key: string) -> UiExpr {
|
|||
}
|
||||
return null
|
||||
}
|
||||
# no space at either end, no two together, no tab or line break: tpl_words would give it back as is
|
||||
function tpl_clean(s: string) -> bool {
|
||||
let n = len(s)
|
||||
if n == 0 { return true }
|
||||
if s[0] == 32 or s[n - 1] == 32 { return false }
|
||||
for i in 0 .. n {
|
||||
let c = s[i]
|
||||
if c == 9 or c == 10 or c == 13 { return false }
|
||||
if c == 32 and s[i + 1] == 32 { return false }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
function el_unit(ui_st: UiState, s: string) -> float {
|
||||
let f = el_num(s)
|
||||
let n = len(s)
|
||||
if n > 3 and s[n - 3..n] == "rem" { return f * el_px(ui_st, 16.0) }
|
||||
if n > 2 and s[n - 2..n] == "em" {
|
||||
if n > 3 and sat(s, n - 3, "rem") { return f * el_px(ui_st, 16.0) }
|
||||
if n > 2 and sat(s, n - 2, "em") {
|
||||
if ui_st.el_cur == null { return f * el_px(ui_st, 16.0) }
|
||||
if ui_st.el_key == "size" and ui_st.el_cur.parent != null { return f * cs_fs(ui_st, ui_st.el_cur.parent) }
|
||||
return f * cs_fs(ui_st, ui_st.el_cur)
|
||||
}
|
||||
if n > 2 and s[n - 2..n] == "vw" { return f * ui_st.ly_vp_w / 100.0 }
|
||||
if n > 2 and s[n - 2..n] == "vh" { return f * ui_st.ly_vp_h / 100.0 }
|
||||
if n > 2 and sat(s, n - 2, "vw") { return f * ui_st.ly_vp_w / 100.0 }
|
||||
if n > 2 and sat(s, n - 2, "vh") { return f * ui_st.ly_vp_h / 100.0 }
|
||||
return el_px(ui_st, f)
|
||||
}
|
||||
# the font size an element has so far in its cascade (its own, else its parent's)
|
||||
|
|
@ -55,7 +55,7 @@ function cs_vars_in(ui_st: mut UiState, n: UiNode, v: Val) -> Val {
|
|||
var found = false
|
||||
var i = 0
|
||||
while i + 4 <= len(s) {
|
||||
if s[i..i + 4] == "var(" {
|
||||
if sat(s, i, "var(") {
|
||||
found = true
|
||||
var j = i + 4
|
||||
var depth = 1
|
||||
|
|
@ -73,7 +73,7 @@ function cs_vars_in(ui_st: mut UiState, n: UiNode, v: Val) -> Val {
|
|||
return Value.str(tpl_words(out + s[at..len(s)]))
|
||||
}
|
||||
function cs_var_ref(ui_st: mut UiState, n: UiNode, inner: string) -> string {
|
||||
let parts = lss_split(inner, 44)
|
||||
let parts = mm_split(ui_st, inner, 44)
|
||||
let v = cs_var(n, tpl_words(parts[0]))
|
||||
if v != null { return v }
|
||||
if len(parts) > 1 { return tpl_words(inner[len(parts[0]) + 1..len(inner)]) }
|
||||
|
|
|
|||
|
|
@ -71,3 +71,14 @@ function vl_binary(op: string, a: Val, b: Val) -> Val {
|
|||
# a value as text, whatever kind it is: a component's string prop given a number (label="{3}") reads
|
||||
# "3", not nothing
|
||||
export function ui_val_text(v: Val) -> string { return vl_text(v) }
|
||||
# vl_text for what is asked per element per frame: a small whole number's text comes from the table
|
||||
# made once (mm_int) rather than being written out again
|
||||
function vl_text_u(ui_st: mut UiState, v: Val) -> string {
|
||||
let k = Value.kind(v)
|
||||
if k == 1 { return mm_int(ui_st, Value.as_int(v)) }
|
||||
if k == 2 or k == 7 {
|
||||
let f = Value.as_float(v)
|
||||
if f == float(int(f)) { return mm_int(ui_st, int(f)) }
|
||||
}
|
||||
return vl_text(v)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -479,6 +479,7 @@ namespace Value {
|
|||
alias as_float(value) = value_as_float
|
||||
alias as_str(value) = value_as_str
|
||||
alias free(value) = value_free
|
||||
alias clear(value) = value_clear
|
||||
}
|
||||
namespace Json {
|
||||
alias encode(value) = json_encode
|
||||
|
|
|
|||
|
|
@ -24,12 +24,22 @@ property Val {
|
|||
kids: []Val
|
||||
}
|
||||
|
||||
# a number, a string or a null is one record; only a list or an object carries lists (made when first
|
||||
# filled) - three allocations for every scalar was most of what a UI frame made and never gave back
|
||||
function value_new(tag: int) -> Val {
|
||||
let v = new Val
|
||||
v.tag = tag
|
||||
if tag == 5 or tag == 6 { value_lists(v) }
|
||||
return v
|
||||
}
|
||||
function value_lists(v: Val) -> void {
|
||||
if v.kids != null { return }
|
||||
v.keys = new []pointer
|
||||
v.kids = new []Val
|
||||
return v
|
||||
}
|
||||
function value_n(v: Val) -> int {
|
||||
if v.kids == null { return 0 }
|
||||
return len(v.kids)
|
||||
}
|
||||
|
||||
# --- constructors -----------------------------------------------------------
|
||||
|
|
@ -43,8 +53,13 @@ function value_float(x: float) -> Val { let v = value_new(7); v.num = float_bits
|
|||
function value_object() -> Val { return value_new(6) }
|
||||
|
||||
# --- builders (return the container, so calls chain) ------------------------
|
||||
function value_add(list: Val, item: Val) -> Val { push(list.kids, item); return list }
|
||||
function value_add(list: Val, item: Val) -> Val {
|
||||
value_lists(list)
|
||||
push(list.kids, item)
|
||||
return list
|
||||
}
|
||||
function value_put(obj: Val, key: pointer, item: Val) -> Val {
|
||||
value_lists(obj)
|
||||
var i = 0
|
||||
while i < len(obj.keys) { if obj.keys[i] == key { obj.kids[i] = item; return obj }; i += 1 }
|
||||
push(obj.keys, key); push(obj.kids, item)
|
||||
|
|
@ -53,7 +68,13 @@ function value_put(obj: Val, key: pointer, item: Val) -> Val {
|
|||
|
||||
# --- accessors --------------------------------------------------------------
|
||||
function value_kind(v: Val) -> int { return v.tag }
|
||||
function value_count(v: Val) -> int { return len(v.kids) }
|
||||
function value_count(v: Val) -> int { return value_n(v) }
|
||||
# a list or an object emptied in place, its room kept - for one filled again every frame
|
||||
function value_clear(v: Val) -> void {
|
||||
if v.kids == null { return }
|
||||
List.clear(v.kids)
|
||||
List.clear(v.keys)
|
||||
}
|
||||
function value_as_int(v: Val) -> int {
|
||||
if v.tag == 7 { return int(float_from_bits(v.num)) }
|
||||
return v.num
|
||||
|
|
@ -66,21 +87,21 @@ function value_as_float(v: Val) -> float {
|
|||
}
|
||||
function value_as_str(v: Val) -> string { if v.txt == null { return "" }; return v.txt }
|
||||
function value_at(list: Val, i: int) -> Val {
|
||||
if i < 0 or i >= len(list.kids) { return value_null() }
|
||||
if i < 0 or i >= value_n(list) { return value_null() }
|
||||
return list.kids[i]
|
||||
}
|
||||
function value_key_at(obj: Val, i: int) -> string {
|
||||
if i < 0 or i >= len(obj.keys) { return "" }
|
||||
if i < 0 or i >= value_n(obj) { return "" }
|
||||
return obj.keys[i]
|
||||
}
|
||||
function value_get(obj: Val, key: pointer) -> Val {
|
||||
var i = 0
|
||||
while i < len(obj.keys) { if obj.keys[i] == key { return obj.kids[i] }; i += 1 }
|
||||
while i < value_n(obj) { if obj.keys[i] == key { return obj.kids[i] }; i += 1 }
|
||||
return value_null()
|
||||
}
|
||||
function value_has(obj: Val, key: pointer) -> int {
|
||||
var i = 0
|
||||
while i < len(obj.keys) { if obj.keys[i] == key { return 1 }; i += 1 }
|
||||
while i < value_n(obj) { if obj.keys[i] == key { return 1 }; i += 1 }
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +153,7 @@ function json_encode(v: Val) -> string {
|
|||
if v.tag == 5 {
|
||||
var out = "["
|
||||
var i = 0
|
||||
while i < len(v.kids) {
|
||||
while i < value_n(v) {
|
||||
if i > 0 { out += "," }
|
||||
out += json_encode(v.kids[i])
|
||||
i += 1
|
||||
|
|
@ -141,7 +162,7 @@ function json_encode(v: Val) -> string {
|
|||
}
|
||||
var out = "{"
|
||||
var i = 0
|
||||
while i < len(v.keys) {
|
||||
while i < value_n(v) {
|
||||
if i > 0 { out += "," }
|
||||
out = out + json_quote(v.keys[i]) + ":" + json_encode(v.kids[i])
|
||||
i += 1
|
||||
|
|
@ -176,9 +197,11 @@ function json_parse(s: pointer) -> Val {
|
|||
# a node or hold a literal, is not for this (Ludic has no collector; plan 23 of maroon-lake).
|
||||
function value_free(v: Val) -> void {
|
||||
if v == null { return }
|
||||
for i in 0 .. len(v.kids) { value_free(v.kids[i]) }
|
||||
free(v.kids)
|
||||
free(v.keys)
|
||||
if v.kids != null {
|
||||
for i in 0 .. len(v.kids) { value_free(v.kids[i]) }
|
||||
free(v.kids)
|
||||
free(v.keys)
|
||||
}
|
||||
free(v)
|
||||
}
|
||||
function json_free(v: Val) -> void { value_free(v) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue