def image.layout.sized

gralha-svg-render@0.1.0.1 · svg.bend:2720

import gralha-svg-render@0.1.0.1/svg.bend as Svg
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
import gralha-xml-doc@0.1.0.1/xml.bend as XML

2720def image.layout.sized(+as: List<&2, XML.Attr>, +values: List<&2, F32>, +vw: F32, +vh: F32) -> List<&2, XML.Attr>:
2721  +iw = U.nth(values, 0n, 300.0)
2722  +ih = U.nth(values, 1n, 150.0)
2723  +ratio = U.nth(values, 2n, 0.0)
2724  +aw = U.string.equal(XML.attr.get(as, "width", "auto"), "auto")
2725  +ah = U.string.equal(XML.attr.get(as, "height", "auto"), "auto")
2726  +rw = dimension(as, "width", vw, "0")
2727  +rh = dimension(as, "height", vh, "0")
2728  +w = U.choose(F32, aw, U.choose(F32, ah, iw, U.choose(F32, F32.is_gt(ratio, 0.0), (rh * ratio : F32), iw)), rw)
2729  +h = U.choose(F32, ah, U.choose(F32, aw, ih, U.choose(F32, F32.is_gt(ratio, 0.0), (rw / U.max(ratio, 0.000001) : F32), ih)), rh)
2730  Con{XML.Attr{"width", F32.show(w)}, Con{XML.Attr{"height", F32.show(h)}, as}}

Uses (13)

Used by (1)