feat(ui): linear-gradient backgrounds, object-fit and aspect-ratio
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
abf45ef9db
commit
7605a0253c
18 changed files with 248 additions and 4 deletions
33
packages/ludic.ui/attr_fit.ludic
Normal file
33
packages/ludic.ui/attr_fit.ludic
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# attr_fit.ludic - aspect-ratio (16 / 9, or 1.5) and object-fit (fill, contain, cover, none,
|
||||
# scale-down) for pictures and natives, and a list split at its top-level commas
|
||||
function el_fit_props(n: UiNode, key: string, s: string) -> bool {
|
||||
if key == "aspect-ratio" {
|
||||
let parts = lss_split(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 { 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue