# dump.ludic - a laid-out tree, for a test or a look # every node and where it went, one line each - for a test, or a look at a layout @alloc_ok("developer builds only, once, under LUDIC_UI_DUMP") export function ui_dump(n: UiNode, depth: int) -> string { var pad = "" for d in 0 .. depth { pad = pad + " " } var out = `{pad}{dp_name(n)} {int(n.x)},{int(n.y)} {int(n.cw)}x{int(n.ch)}{dp_style(n)} {n.text}\n` if n.children != null { for i in 0 .. len(n.children) { out = out + ui_dump(n.children[i], depth + 1) } } return out } # tag#id.class.class, or the kind of a node the template did not name @alloc_ok("developer builds only, once, under LUDIC_UI_DUMP") function dp_name(n: UiNode) -> string { var s = n.tag if s == "" { s = `({n.kind})` } if n.id != "" { s = s + "#" + n.id } if n.classes != null { for i in 0 .. len(n.classes) { s = s + "." + n.classes[i] } } return s } # the computed styles that differ from an element's defaults @alloc_ok("developer builds only, once, under LUDIC_UI_DUMP") function dp_style(n: UiNode) -> string { var s = "" if n.size > 0.0 { s = s + ` font {int(n.size)}` } if n.fg >= 0 { s = s + ` color {ui_hex(n.fg)}` } if n.bg >= 0 and n.bg_a > 0.0 { s = s + ` bg {ui_hex(n.bg)}` } if n.alpha < 1.0 { s = s + ` opacity {n.alpha}` } if n.pt + n.pr + n.pb + n.pl > 0.0 { s = s + ` pad {int(n.pt)} {int(n.pr)} {int(n.pb)} {int(n.pl)}` } if n.mt + n.mr + n.mb + n.ml > 0.0 { s = s + ` margin {int(n.mt)} {int(n.mr)} {int(n.mb)} {int(n.ml)}` } if n.grow > 0.0 { s = s + ` grow {n.grow}` } if n.pos > 0 { s = s + ` pos {n.pos} z {n.z}` } if not n.enabled { s = s + " disabled" } if s == "" { return "" } return " [" + s[1..len(s)] + "]" }