feat(ui): ui_scale and ui_box, on-submit, zoom (and a length over a length in calc), on-hold
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3d2a103dfb
commit
ec9a650e65
24 changed files with 323 additions and 23 deletions
37
packages/ludic.ui/zoom.ludic
Normal file
37
packages/ludic.ui/zoom.ludic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# zoom.ludic - zoom: 0.8 (or 80%, or calc(), min() and the rest: min(1, calc(100vw / 1800px))) makes
|
||||
# an element and everything inside it that much larger or smaller, its lengths, its text and its
|
||||
# layout; zooms multiply down the tree. A length in px is zoomed as it is read (el_px).
|
||||
function el_zoom(n: UiNode, s0: string) -> void {
|
||||
let s = tpl_words(s0)
|
||||
var z = 1.0
|
||||
if ca_is(s) {
|
||||
if ca_eval(s) {
|
||||
z = ca_num
|
||||
if not ca_bare { ui_err(`zoom: {s} - a zoom is a plain number (divide a length by a length)`) }
|
||||
}
|
||||
} else if len(s) > 1 and s[len(s) - 1] == 37 { z = el_num(s) / 100.0 } else if s != "normal" { z = el_num(s) }
|
||||
if z <= 0.0 { z = 1.0 }
|
||||
nx(n).zoom = z
|
||||
}
|
||||
function zm_own(n: UiNode) -> float {
|
||||
if n.ex == null { return 1.0 }
|
||||
return n.ex.zoom
|
||||
}
|
||||
# every zoom from this element out
|
||||
function zm_all(n: UiNode) -> float {
|
||||
var z = 1.0
|
||||
var at = n
|
||||
while at != null {
|
||||
z = z * zm_own(at)
|
||||
at = at.parent
|
||||
}
|
||||
return z
|
||||
}
|
||||
# a length of `v` design pixels on the element being styled: the renderer's scale and every zoom
|
||||
# around it (its own too, except while its zoom itself is read)
|
||||
function el_px(v: float) -> float {
|
||||
if el_cur == null { return ui_px(v) }
|
||||
if el_key == "zoom" and el_cur.parent != null { return ui_px(v) * zm_all(el_cur.parent) }
|
||||
if el_key == "zoom" { return ui_px(v) }
|
||||
return ui_px(v) * zm_all(el_cur)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue