33 lines
1.2 KiB
Text
33 lines
1.2 KiB
Text
# attr_fit.ludic - aspect-ratio (16 / 9, or 1.5), object-fit (fill, contain, cover, none, scale-down)
|
|
# 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 = 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 }
|
|
nx(n).ratio = Math.max(r, 0.0)
|
|
} else if key == "object-fit" {
|
|
let w = tpl_words(s)
|
|
var k = 0
|
|
if w == "contain" { k = 1 } else if w == "cover" { k = 2 } else if w == "none" { k = 3 } else if w == "scale-down" { k = 4 }
|
|
nx(n).fit_obj = k
|
|
} else if key == "zoom" { el_zoom(ui_st, n, s) } else { return false }
|
|
return true
|
|
}
|
|
# "a, rgba(1, 2, 3, 0.5) 40%, b" -> its three parts
|
|
function el_commas(s: string) -> []string {
|
|
let out = new []string
|
|
var at = 0
|
|
var depth = 0
|
|
for i in 0 .. len(s) {
|
|
if s[i] == 40 { depth += 1 }
|
|
if s[i] == 41 { depth -= 1 }
|
|
if s[i] == 44 and depth == 0 {
|
|
push(out, s[at..i])
|
|
at = i + 1
|
|
}
|
|
}
|
|
push(out, s[at..len(s)])
|
|
return out
|
|
}
|