ludic/packages/ludic.ui/zoom.ludic

38 lines
1.5 KiB
Text

# 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(ui_st: mut UiState, n: UiNode, s0: string) -> void {
let s = tpl_words(s0)
var z = 1.0
if ca_is(s) {
if ca_eval(ui_st, s) {
z = ui_st.ca_num
@alloc_ok("only when a template is wrong: a broken screen, never a working one")
if not ui_st.ca_bare { ui_err(ui_st, `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(ui_st: UiState, v: float) -> float {
if ui_st.el_cur == null { return ui_px(ui_st, v) }
if ui_st.el_key == "zoom" and ui_st.el_cur.parent != null { return ui_px(ui_st, v) * zm_all(ui_st.el_cur.parent) }
if ui_st.el_key == "zoom" { return ui_px(ui_st, v) }
return ui_px(ui_st, v) * zm_all(ui_st.el_cur)
}