ludic.ui: no number made text to be read back - a style handler returns before any text for a key not its own, grow/alpha/animations/scroll read numbers as numbers, el_secs split once per text, a tooltip translated when its title changes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5f2900ffda
commit
706c7abc55
9 changed files with 39 additions and 9 deletions
|
|
@ -75,11 +75,11 @@ function an_at(ui_st: mut UiState, n: UiNode, k: UiKeyframes, t: float) -> void
|
|||
let a = k.rules[lo]
|
||||
let b = k.rules[hi]
|
||||
for i in 0 .. len(a.keys) {
|
||||
let va = el_num(vl_text(ui_eval(ui_st, a.vals[i], n.env)))
|
||||
let va = el_numv(ui_st, ui_eval(ui_st, a.vals[i], n.env))
|
||||
var vb = va
|
||||
for j in 0 .. len(b.keys) {
|
||||
if b.keys[j] == a.keys[i] { vb = el_num(vl_text(ui_eval(ui_st, b.vals[j], n.env))) }
|
||||
if b.keys[j] == a.keys[i] { vb = el_numv(ui_st, ui_eval(ui_st, b.vals[j], n.env)) }
|
||||
}
|
||||
el_apply(ui_st, n, a.keys[i], Value.float(va + (vb - va) * f))
|
||||
el_apply(ui_st, n, a.keys[i], uv_float(ui_st, va + (vb - va) * f))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,13 @@ 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
|
||||
}
|
||||
const EL_KEYS_FLEX: string = " align dir display flex grow justify self talign wrap "
|
||||
function el_flex(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
if not lk_in(EL_KEYS_FLEX, key) { return false } # not one of its keys: no text made for it
|
||||
if key == "grow" {
|
||||
n.grow = el_numv(ui_st, v)
|
||||
return true
|
||||
}
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "dir" {
|
||||
n.dir = UI_COL
|
||||
|
|
@ -55,7 +61,13 @@ function el_flex(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
|||
} 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
|
||||
}
|
||||
const EL_KEYS_LOOK: string = " alpha bg border border-bottom border-color border-left border-right border-top border-width color enabled size "
|
||||
function el_look(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
if not lk_in(EL_KEYS_LOOK, key) { return false } # not one of its keys: no text made for it
|
||||
if key == "alpha" {
|
||||
n.alpha = el_numv(ui_st, v)
|
||||
return true
|
||||
}
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# attr_edge.ludic - border-radius, outline (and its width, colour and offset), scrollbar-color
|
||||
const EL_KEYS_EDGE: string = " animation background-image border-image border-radius box-shadow outline outline-color outline-offset outline-width scrollbar-color transition "
|
||||
function el_edge(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
if not lk_in(EL_KEYS_EDGE, key) { return false } # not one of its keys: no text made for it
|
||||
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)
|
||||
|
|
@ -8,7 +10,7 @@ function el_edge(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
|||
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(tw(ui_st, s)) { nx(n).grad = gr_parse(ui_st, s) } else if key == "background-image" { n.bg_img = el_url_u(ui_st, 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 }
|
||||
} else if key == "background-image" and gr_is(tw(ui_st, s)) { nx(n).grad = gr_parse(ui_st, s) } else if key == "background-image" { n.bg_img = el_url_u(ui_st, 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(ui_st, s) } else { return false }
|
||||
return true
|
||||
}
|
||||
# url(path) or url("path") -> path
|
||||
|
|
@ -77,12 +79,12 @@ function el_animation(ui_st: mut UiState, n: UiNode, s: string) -> void {
|
|||
n.anim = ""
|
||||
for i in 0 .. len(parts) {
|
||||
let p = parts[i]
|
||||
if p == "infinite" { n.anim_loop = true } else if p == "alternate" { n.anim_alt = true } else if len(p) > 0 and ((p[0] >= 48 and p[0] <= 57) or p[0] == 46) { n.anim_dur = el_secs(p) } else if len(p) > 0 and n.anim == "" and p != "none" { n.anim = p }
|
||||
if p == "infinite" { n.anim_loop = true } else if p == "alternate" { n.anim_alt = true } else if len(p) > 0 and ((p[0] >= 48 and p[0] <= 57) or p[0] == 46) { n.anim_dur = el_secs(ui_st, p) } else if len(p) > 0 and n.anim == "" and p != "none" { n.anim = p }
|
||||
}
|
||||
}
|
||||
# the first time in `0.25s` or `250ms`
|
||||
function el_secs(s: string) -> float {
|
||||
let parts = lss_split(s, 32)
|
||||
function el_secs(ui_st: mut UiState, s: string) -> float {
|
||||
let parts = mm_split(ui_st, s, 32)
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# 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)
|
||||
const EL_KEYS_MORE: string = " line-height order pointer-events shrink text-fit text-shadow aspect-ratio object-fit zoom " # el_fit_props's too
|
||||
function el_more(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
if not lk_in(EL_KEYS_MORE, key) { return false } # not one of its keys: no text made for it
|
||||
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 = tw(ui_st, 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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# attr_place.ludic - position and its insets, z-index, overflow, white-space and text-overflow
|
||||
const EL_KEYS_PLACE_PROP: string = " bottom inset left overflow overflow-y position right text-overflow top white-space z-index "
|
||||
function el_place_prop(ui_st: mut UiState, n: UiNode, key: string, v: Val) -> bool {
|
||||
if not lk_in(EL_KEYS_PLACE_PROP, key) { return false } # not one of its keys: no text made for it
|
||||
let s = vl_text_u(ui_st, v)
|
||||
if key == "position" {
|
||||
n.pos = 0
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ export state UiState {
|
|||
ca_used: int = 0
|
||||
ca_args: [][]CaVal = new [][]CaVal
|
||||
ca_depth: int = 0
|
||||
tt_src: string = null # tooltip.ludic: the title tt_text was translated from
|
||||
fit_out: []float = new []float # draw_content.ludic: an image's box, kept
|
||||
r3n_cut: []float = new []float # render3d_nine.ludic: a nine-slice's edges, kept
|
||||
r3n_xs: []float = new []float
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ function sc_held(ui_st: mut UiState, n: UiNode, off: float, live: bool) -> float
|
|||
ui_st.sc_want_px = pxs
|
||||
}
|
||||
let v = ui_attr(n, "scroll-top")
|
||||
if Value.kind(v) != 0 { at = ui_px(ui_st, el_num(vl_text(v))) }
|
||||
if Value.kind(v) != 0 { at = ui_px(ui_st, el_numv(ui_st, v)) }
|
||||
return at
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,16 @@ function tt_track(ui_st: mut UiState, root: UiNode, x: float, y: float) -> void
|
|||
ui_st.tt_key = ""
|
||||
return
|
||||
}
|
||||
let title = ui_attr_text(n, "title")
|
||||
if n.key != ui_st.tt_key {
|
||||
ui_st.tt_key = n.key
|
||||
ui_st.tt_since = an_now(ui_st)
|
||||
ui_st.tt_src = null
|
||||
}
|
||||
if ui_st.tt_src == null or title != ui_st.tt_src { # translated when the element or its title changes, not a frame
|
||||
ui_st.tt_src = title
|
||||
ui_st.tt_text = tt_translate(ui_st, n, title)
|
||||
}
|
||||
ui_st.tt_text = tt_translate(ui_st, n, ui_attr_text(n, "title"))
|
||||
ui_st.tt_x = px
|
||||
ui_st.tt_y = py
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,3 +79,9 @@ function vl_text_u(ui_st: mut UiState, v: Val) -> string {
|
|||
}
|
||||
return vl_text(v)
|
||||
}
|
||||
# a value as a number: a number read as one, only text parsed (a float's text written per frame to be
|
||||
# read straight back was a leak - an animation's opacity, a flex-grow)
|
||||
function el_numv(ui_st: mut UiState, v: Val) -> float {
|
||||
if vl_num(v) { return Value.as_float(v) }
|
||||
return el_num(vl_text_u(ui_st, v))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue