# layout.ludic - flex layout on the CSS box model, top-down: a box is told how wide it may be, # measures its content at that width (so a wrapping row knows how tall it is), then places each # child. A size is the border box: padding and border inside it, margin outside it. function ly_measure(ui_st: mut UiState, n: UiNode, avail: float, size: float, fg: int) -> void { n.rsize = size * zm_own(n) if n.size > 0.0 { n.rsize = n.size } n.rfg = fg n.rfg_a = ui_st.ly_fg_a if n.fg != UI_INHERIT { n.rfg = n.fg n.rfg_a = n.fg_a } ui_st.ly_fg_a = n.rfg_a n.mw = ly_hin(n) n.mh = ly_vin(n) if n.kind == UI_TEXT { ly_measure_text(ui_st, n, avail) } if n.kind == UI_NATIVE and n.native.measure != null { let base_w = n.mw let base_h = n.mh n.mw = 0.0 n.mh = 0.0 n.native.measure(n, avail) n.mw = n.mw + base_w n.mh = n.mh + base_h } if n.kind == UI_IMAGE { n.mw = n.mw + n.rsize n.mh = n.mh + n.rsize } var fixed_w = n.w if n.w_pct > 0.0 { fixed_w = ly_pw(n, avail) } if (n.kind == UI_BOX or n.kind == UI_SCROLL) and n.children != null { var inner = avail - n.ml - n.mr if fixed_w >= 0.0 { inner = fixed_w } inner = ly_clamp(inner, n.min_w, n.max_w) - ly_hin(n) if n.dir == UI_ROW and n.wrap { ly_measure_wrap(ui_st, n, inner) } else { ly_measure_box(ui_st, n, inner) } } n.content_h = n.mh if fixed_w >= 0.0 { n.mw = fixed_w } if n.h >= 0.0 { n.mh = n.h } ly_ratio(n, fixed_w, avail) n.mw = ly_clamp(n.mw, n.min_w, n.max_w) n.mh = ly_clamp(n.mh, n.min_h, n.max_h) ly_min_note(n) } function ly_hin(n: UiNode) -> float { return n.pl + n.pr + n.bl + n.br } function ly_vin(n: UiNode) -> float { return n.pt + n.pb + n.bt + n.bb } function ly_clamp(v: float, lo: float, hi: float) -> float { var out = v if hi > 0.0 and out > hi { out = hi } if out < lo { out = lo } return out }