<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>past the boonies</title>
    <link rel="self" type="application/atom+xml" href="https://pasttheboonies.com/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://pasttheboonies.com"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-12-01T00:00:00+00:00</updated>
    <id>https://pasttheboonies.com/atom.xml</id>
    <entry xml:lang="en">
        <title>blit: immediate (yet deferred) mode UI</title>
        <published>2026-12-01T00:00:00+00:00</published>
        <updated>2026-12-01T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://pasttheboonies.com/jots/blit/"/>
        <id>https://pasttheboonies.com/jots/blit/</id>
        
        <content type="html" xml:base="https://pasttheboonies.com/jots/blit/">&lt;p&gt;I started working on &lt;a rel=&quot;external&quot; href=&quot;https://github.com/nicoburniske/blit&quot;&gt;blit&lt;/a&gt; as an experiment 5 months ago. a few rewrites later, it has a zero-dependency core, a terminal &amp;amp; gpu backend, and a very fast software renderer.&lt;/p&gt;
&lt;p&gt;at &lt;a rel=&quot;external&quot; href=&quot;https://foundation.xyz&quot;&gt;Foundation&lt;/a&gt; our device runs KeyOS, a custom microkernel OS, on a single core 500 MHz Cortex-A5 with 128 MB of RAM and no GPU. we picked &lt;a rel=&quot;external&quot; href=&quot;https://slint.dev/&quot;&gt;Slint&lt;/a&gt; because it’s one of the few rust UI frameworks with a real software renderer. it topped out at 30 fps on our 480×800 LCD. I felt like the hardware could do more, so I started tinkering.&lt;/p&gt;
&lt;p&gt;to understand where blit ended up, it helps to look at how most UI frameworks work and where they fall short.&lt;/p&gt;
&lt;h2 id=&quot;retained-mode&quot;&gt;retained mode&lt;/h2&gt;
&lt;p&gt;most UI frameworks operate in &lt;a rel=&quot;external&quot; href=&quot;https://caseymuratori.com/blog_0001&quot;&gt;retained mode&lt;/a&gt;. the code you write can look simple. here’s a button that shows a panel in &lt;a rel=&quot;external&quot; href=&quot;https://dioxuslabs.com/&quot;&gt;Dioxus&lt;/a&gt;&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-dioxus-1&quot;&gt;&lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fn-dioxus&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; app&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Element&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; mut&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; show_details&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; use_signal&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-7&quot;&gt; false&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-6 z-d-b&quot;&gt;    rsx!&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        button&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;            onclick&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; move&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; show_details&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;toggle&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;toggle&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;        if&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; show_details&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;            p&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;some details&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;it looks like rust, but &lt;code&gt;rsx!&lt;/code&gt; is a procedural macro with its own DSL.&lt;/p&gt;
&lt;p&gt;also note how &lt;code&gt;app()&lt;/code&gt; doesn’t ‘run’ your UI. it returns your UI as a value, and the runtime interprets that value. and &lt;code&gt;show_details&lt;/code&gt; isn’t a &lt;code&gt;bool&lt;/code&gt;. it’s a &lt;code&gt;Signal&amp;lt;bool&amp;gt;&lt;/code&gt; that tracks who reads it, so the runtime knows which parts of the UI to update when it changes.&lt;/p&gt;
&lt;p&gt;here’s what an &lt;code&gt;Element&lt;/code&gt; &lt;a rel=&quot;external&quot; href=&quot;https://github.com/DioxusLabs/dioxus/blob/0a7242a2a72b08975584bf8ecb05076a5ee0b9c7/packages/vdom/src/nodes.rs&quot;&gt;actually is&lt;/a&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Element&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Result&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;VNode&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; RenderError&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; VNode&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    vnode&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Rc&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;VNodeInner&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; VNodeInner&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    template&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Template&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    dynamic_nodes&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Vec&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;DynamicNode&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    dynamic_attrs&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Vec&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Attribute&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; DynamicNode&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;    Component&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;VComponent&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;    Text&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;VText&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;    Fragment&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;VNode&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; VComponent&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    driver&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Rc&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;dyn&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; RenderDriver&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    props&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Box&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;dyn&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; AnyProps&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; AttributeValue&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;    Listener&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Rc&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;RefCell&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;dyn&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; FnMut&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Event&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;dyn&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Any&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;it’s a tree of &lt;code&gt;Rc&lt;/code&gt; and &lt;code&gt;Box&lt;/code&gt; scattered on the heap. everything the runtime does means chasing those pointers:&lt;/p&gt;
&lt;svg style=&quot;display: block; margin: 1.5rem 0; font: 13px ui-monospace, monospace; fill: var(--muted)&quot; viewBox=&quot;0 0 650 280&quot; role=&quot;img&quot; aria-label=&quot;the toggle example as a tree, app with onclick and its closure on one side and the if with its p on the other, with each node pointing to a random slot in a heap full of unrelated allocations&quot;&gt;
  &lt;g style=&quot;stroke: var(--muted); stroke-width: 1.5&quot;&gt;
    &lt;line x1=&quot;325&quot; y1=&quot;56&quot; x2=&quot;150&quot; y2=&quot;80&quot;/&gt;
    &lt;line x1=&quot;325&quot; y1=&quot;56&quot; x2=&quot;500&quot; y2=&quot;80&quot;/&gt;
    &lt;line x1=&quot;150&quot; y1=&quot;106&quot; x2=&quot;230&quot; y2=&quot;130&quot;/&gt;
  &lt;/g&gt;
  &lt;g style=&quot;fill: none; stroke: var(--link); stroke-width: 1.5; stroke-dasharray: 4 4&quot;&gt;
    &lt;line x1=&quot;325&quot; y1=&quot;56&quot; x2=&quot;325&quot; y2=&quot;212&quot;/&gt;
    &lt;line x1=&quot;150&quot; y1=&quot;106&quot; x2=&quot;175&quot; y2=&quot;212&quot;/&gt;
    &lt;line x1=&quot;500&quot; y1=&quot;106&quot; x2=&quot;565&quot; y2=&quot;212&quot;/&gt;
    &lt;line x1=&quot;230&quot; y1=&quot;156&quot; x2=&quot;505&quot; y2=&quot;212&quot;/&gt;
  &lt;/g&gt;
  &lt;g style=&quot;fill: var(--block)&quot;&gt;
    &lt;rect x=&quot;290&quot; y=&quot;30&quot; width=&quot;70&quot; height=&quot;26&quot;/&gt;
    &lt;rect x=&quot;115&quot; y=&quot;80&quot; width=&quot;70&quot; height=&quot;26&quot;/&gt;
    &lt;rect x=&quot;465&quot; y=&quot;80&quot; width=&quot;70&quot; height=&quot;26&quot;/&gt;
    &lt;rect x=&quot;195&quot; y=&quot;130&quot; width=&quot;70&quot; height=&quot;26&quot;/&gt;
  &lt;/g&gt;
  &lt;g style=&quot;fill: var(--bg)&quot; text-anchor=&quot;middle&quot;&gt;
    &lt;text x=&quot;325&quot; y=&quot;48&quot;&gt;app&lt;/text&gt;
    &lt;text x=&quot;150&quot; y=&quot;98&quot;&gt;onclick&lt;/text&gt;
    &lt;text x=&quot;500&quot; y=&quot;98&quot;&gt;if&lt;/text&gt;
    &lt;text x=&quot;230&quot; y=&quot;148&quot;&gt;closure&lt;/text&gt;
  &lt;/g&gt;
  &lt;rect style=&quot;fill: none; stroke: var(--muted)&quot; x=&quot;10&quot; y=&quot;210&quot; width=&quot;630&quot; height=&quot;40&quot;/&gt;
  &lt;g style=&quot;fill: var(--muted); opacity: 0.25&quot;&gt;
    &lt;rect x=&quot;11&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;41&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;101&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;131&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;221&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;251&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;341&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;371&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;431&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;461&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;581&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;611&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;191&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;281&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;401&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;521&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
  &lt;/g&gt;
  &lt;g style=&quot;fill: var(--block)&quot;&gt;
    &lt;rect x=&quot;161&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;311&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;491&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
    &lt;rect x=&quot;551&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
  &lt;/g&gt;
  &lt;g&gt;
    &lt;animate attributeName=&quot;opacity&quot; values=&quot;1;1;0.15;0.15;1&quot; keyTimes=&quot;0;0.45;0.5;0.95;1&quot; dur=&quot;4s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    &lt;line style=&quot;stroke: var(--muted); stroke-width: 1.5&quot; x1=&quot;500&quot; y1=&quot;106&quot; x2=&quot;420&quot; y2=&quot;130&quot;/&gt;
    &lt;line style=&quot;stroke: var(--link); stroke-width: 1.5; stroke-dasharray: 4 4&quot; x1=&quot;420&quot; y1=&quot;156&quot; x2=&quot;85&quot; y2=&quot;212&quot;/&gt;
    &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;385&quot; y=&quot;130&quot; width=&quot;70&quot; height=&quot;26&quot;/&gt;
    &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;420&quot; y=&quot;148&quot; text-anchor=&quot;middle&quot;&gt;p&lt;/text&gt;
    &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;71&quot; y=&quot;212&quot; width=&quot;28&quot; height=&quot;36&quot;/&gt;
  &lt;/g&gt;
  &lt;text x=&quot;10&quot; y=&quot;270&quot;&gt;heap&lt;/text&gt;
&lt;/svg&gt;
&lt;p&gt;React, Flutter, SwiftUI, and Slint all kinda look like this.&lt;/p&gt;
&lt;p&gt;now why does this hurt? CPUs don’t read one byte at a time. they grab memory in small chunks (usually 64 bytes) and keep recent chunks close by in cache.&lt;/p&gt;
&lt;p&gt;here’s how long a memory load takes on my pc&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-machine-1&quot;&gt;&lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fn-machine&quot;&gt;[2]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;memory&lt;/th&gt;&lt;th&gt;latency&lt;/th&gt;&lt;th&gt;cpu cycles&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;L1&lt;/td&gt;&lt;td&gt;~1 ns&lt;/td&gt;&lt;td&gt;~5&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;L2&lt;/td&gt;&lt;td&gt;~4 ns&lt;/td&gt;&lt;td&gt;~20&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;L3&lt;/td&gt;&lt;td&gt;~18 ns&lt;/td&gt;&lt;td&gt;~100&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;RAM&lt;/td&gt;&lt;td&gt;~92 ns&lt;/td&gt;&lt;td&gt;~500&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;modern CPUs spend a lot of effort trying to guess what memory your program will read next so it can already be waiting in cache before you ask for it. if you’re walking through an array, that pattern is easy to spot, so upcoming chunks get pulled in ahead of time.&lt;/p&gt;
&lt;p&gt;following pointers scattered across a heap breaks that. to know where a child lives, you first have to read the pointer inside its parent, and the CPU can’t fetch the child ahead of time when it doesn’t even know its address yet. worse, every time you jump to a random spot in memory, the CPU still grabs a whole chunk of whatever unrelated data happens to sit next to it, pushing useful things out of cache. if what you need isn’t in cache, the CPU has to sit around for ~500 cycles waiting on RAM, which is a couple thousand operations it could have done instead.&lt;/p&gt;
&lt;h2 id=&quot;immediate-mode&quot;&gt;immediate mode&lt;/h2&gt;
&lt;p&gt;immediate mode makes a different bet:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;rebuilding the UI every frame costs less than the bookkeeping to avoid it.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;here’s the same panel in &lt;a rel=&quot;external&quot; href=&quot;https://www.egui.rs/&quot;&gt;egui&lt;/a&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; App&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    show_details&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-7&quot;&gt; bool&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;impl&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; App&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt; egui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Ui&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;        if&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;toggle&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;clicked&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;show_details &lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; !&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;show_details&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;        if&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;show_details &lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;            ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;some details&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this code runs each frame. &lt;code&gt;ui.button&lt;/code&gt; measures and positions the button, records drawing commands, and returns whether it was clicked.&lt;/p&gt;
&lt;p&gt;there is a beauty in this simplicity:&lt;/p&gt;
&lt;h3 id=&quot;you-own-your-state&quot;&gt;you own your state&lt;/h3&gt;
&lt;p&gt;it’s a plain &lt;code&gt;bool&lt;/code&gt; in a struct you own. the widget borrows it for one call.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;checkbox&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;dark_mode&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;dark mode&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in retained mode the same &lt;code&gt;bool&lt;/code&gt; moves into the framework. you read it in one place and write it back in a callback.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; mut&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; dark_mode&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; use_signal&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-7&quot;&gt; false&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    r#type&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;checkbox&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    checked&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; dark_mode&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    onchange&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; move&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; dark_mode&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;checked&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;your app ends up built around the framework instead of the other way around.&lt;/p&gt;
&lt;h3 id=&quot;your-program-s-execution-is-already-a-tree&quot;&gt;your program’s execution is &lt;strong&gt;already&lt;/strong&gt; a tree&lt;/h3&gt;
&lt;p&gt;running functions that branch and loop already traces out a tree on the call stack. retained mode has to capture your UI as a data structure first, which means encoding control flow into that structure too.&lt;/p&gt;
&lt;p&gt;in immediate mode, a &lt;code&gt;for&lt;/code&gt; loop is a list, an &lt;code&gt;if&lt;/code&gt; is a conditional widget, and a component is just a function. when the call stack is the UI tree, a normal debugger or profiler actually shows you your own code instead of a framework runtime.&lt;/p&gt;
&lt;h3 id=&quot;built-to-be-embedded&quot;&gt;built to be embedded&lt;/h3&gt;
&lt;p&gt;egui and &lt;a rel=&quot;external&quot; href=&quot;https://github.com/ocornut/imgui&quot;&gt;Dear ImGui&lt;/a&gt; don’t own your window, event loop or renderer. each frame you hand them input and they hand back draw commands.&lt;/p&gt;
&lt;p&gt;that’s why games can embed them for debug tools and editors. the whole UI is one function call inside a frame the game was already drawing.&lt;/p&gt;
&lt;h3 id=&quot;the-trade-off&quot;&gt;the trade-off&lt;/h3&gt;
&lt;p&gt;widgets are laid out immediately as they’re built, and you can’t go back to resize the row or move an earlier widget.&lt;/p&gt;
&lt;p&gt;say I have a row with two rectangles, where &lt;code&gt;B&lt;/code&gt; takes up the remaining width. I want the row to be as tall as its tallest child, with all children centered along the cross axis.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;horizontal&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;add_sized&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt; 20&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt; egui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;add_sized&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;available_width&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt; 60&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt; egui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;svg style=&quot;display: block; margin: 1.5rem 0; font: 14px ui-monospace, monospace; fill: var(--muted)&quot; viewBox=&quot;0 0 650 214&quot; role=&quot;img&quot; aria-label=&quot;a row where A is stuck at the top instead of centered, with B filling the rest&quot;&gt;
  &lt;text x=&quot;20&quot; y=&quot;16&quot;&gt;row&lt;/text&gt;
  &lt;rect style=&quot;fill: none; stroke: var(--muted)&quot; x=&quot;20&quot; y=&quot;24&quot; width=&quot;600&quot; height=&quot;180&quot;/&gt;
  &lt;rect style=&quot;fill: none; stroke: var(--block); stroke-dasharray: 6 6; opacity: 0.5&quot; x=&quot;21&quot; y=&quot;84&quot; width=&quot;118&quot; height=&quot;60&quot;/&gt;
  &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;20&quot; y=&quot;24&quot; width=&quot;120&quot; height=&quot;60&quot;/&gt;
  &lt;rect style=&quot;fill: var(--link); opacity: 0.5&quot; x=&quot;140&quot; y=&quot;24&quot; width=&quot;12&quot; height=&quot;180&quot;/&gt;
  &lt;rect style=&quot;fill: var(--block-dim)&quot; x=&quot;152&quot; y=&quot;24&quot; width=&quot;468&quot; height=&quot;180&quot;/&gt;
  &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;80&quot; y=&quot;59&quot; text-anchor=&quot;middle&quot;&gt;A&lt;/text&gt;
  &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;386&quot; y=&quot;119&quot; text-anchor=&quot;middle&quot;&gt;B&lt;/text&gt;
&lt;/svg&gt;
&lt;p&gt;&lt;code&gt;A&lt;/code&gt; is placed before &lt;code&gt;B&lt;/code&gt; even exists, so it’s stuck at the top instead of centered.&lt;/p&gt;
&lt;h2 id=&quot;blit-immediate-mode-deferred-layout&quot;&gt;blit: immediate mode, deferred layout&lt;/h2&gt;
&lt;p&gt;blit is a portable &lt;code&gt;no_std&lt;/code&gt; UI library with zero dependencies. your code stays immediate mode, while blit retains a little state to avoid immediate mode’s shortcomings.&lt;/p&gt;
&lt;h3 id=&quot;deferred-layout&quot;&gt;deferred layout&lt;/h3&gt;
&lt;p&gt;immediate mode doesn’t require immediate layout. each frame, blit runs three passes: &lt;strong&gt;build&lt;/strong&gt;, &lt;strong&gt;layout&lt;/strong&gt;, then &lt;strong&gt;paint&lt;/strong&gt;. and yes, it’s still very fast.&lt;/p&gt;
&lt;p&gt;here’s the same row in blit:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; mut&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; row&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;layout&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;align&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Align&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Center&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Rectangle&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-7&quot;&gt;BLACK&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Sizing&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;grow&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Rectangle&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-7&quot;&gt;GRAY&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;build&lt;/strong&gt; records the tree. nothing is placed yet.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;node&lt;/th&gt;&lt;th&gt;position&lt;/th&gt;&lt;th&gt;size&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;row&lt;/td&gt;&lt;td&gt;?&lt;/td&gt;&lt;td&gt;?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A&lt;/td&gt;&lt;td&gt;?&lt;/td&gt;&lt;td&gt;40 × 20&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;B&lt;/td&gt;&lt;td&gt;?&lt;/td&gt;&lt;td&gt;? × 60&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;layout&lt;/strong&gt; gives &lt;code&gt;B&lt;/code&gt; the leftover width, sizes the row to fit, then centers &lt;code&gt;A&lt;/code&gt;.&lt;/p&gt;
&lt;svg style=&quot;display: block; margin: 1.5rem 0; font: 14px ui-monospace, monospace; fill: var(--muted)&quot; viewBox=&quot;0 0 650 214&quot; role=&quot;img&quot; aria-label=&quot;layout result: A at 0,20 sized 40×20, B at 44,0 sized 156×60&quot;&gt;
  &lt;text x=&quot;20&quot; y=&quot;16&quot;&gt;0&lt;/text&gt;
  &lt;text x=&quot;138&quot; y=&quot;16&quot; text-anchor=&quot;end&quot;&gt;40&lt;/text&gt;
  &lt;text x=&quot;154&quot; y=&quot;16&quot;&gt;44&lt;/text&gt;
  &lt;text x=&quot;620&quot; y=&quot;16&quot; text-anchor=&quot;end&quot;&gt;200&lt;/text&gt;
  &lt;text x=&quot;628&quot; y=&quot;36&quot;&gt;0&lt;/text&gt;
  &lt;text x=&quot;628&quot; y=&quot;204&quot;&gt;60&lt;/text&gt;
  &lt;rect style=&quot;fill: none; stroke: var(--muted)&quot; x=&quot;20&quot; y=&quot;24&quot; width=&quot;600&quot; height=&quot;180&quot;/&gt;
  &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;20&quot; y=&quot;84&quot; width=&quot;120&quot; height=&quot;60&quot;/&gt;
  &lt;rect style=&quot;fill: var(--link); opacity: 0.5&quot; x=&quot;140&quot; y=&quot;24&quot; width=&quot;12&quot; height=&quot;180&quot;/&gt;
  &lt;rect style=&quot;fill: var(--block-dim)&quot; x=&quot;152&quot; y=&quot;24&quot; width=&quot;468&quot; height=&quot;180&quot;/&gt;
  &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;80&quot; y=&quot;119&quot; text-anchor=&quot;middle&quot;&gt;A&lt;/text&gt;
  &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;386&quot; y=&quot;119&quot; text-anchor=&quot;middle&quot;&gt;B&lt;/text&gt;
&lt;/svg&gt;
&lt;p&gt;&lt;strong&gt;paint&lt;/strong&gt; walks the tree with the solved areas and records draw commands.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;node&lt;/th&gt;&lt;th&gt;command&lt;/th&gt;&lt;th&gt;x&lt;/th&gt;&lt;th&gt;y&lt;/th&gt;&lt;th&gt;size&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;A&lt;/td&gt;&lt;td&gt;rectangle&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;20&lt;/td&gt;&lt;td&gt;40 × 20&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;B&lt;/td&gt;&lt;td&gt;rectangle&lt;/td&gt;&lt;td&gt;44&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;156 × 60&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;layouts aren’t built in. the &lt;code&gt;flex::row()&lt;/code&gt; above is just ordinary code implementing &lt;code&gt;Layout&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;trait&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Layout&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Context&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    type&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Item&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Default&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; fit&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;        &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; LayoutCx&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; C&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt; Self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        axis&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Axis&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;    )&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Fit&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Scalar&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; distribute&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;        &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; LayoutCx&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; C&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt; Self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        axis&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Axis&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        extent&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt; C&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Scalar&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;    )&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Fit&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    min&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; T&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;    natural&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; T&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;blit solves each axis (width, then height) in two passes over the node array:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;fit&lt;/code&gt;&lt;/strong&gt; walks up from the leaves. each leaf reports its &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;natural&lt;/code&gt; size, each parent sizes itself from its children, and every result lands in a &lt;code&gt;fits&lt;/code&gt; array.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;distribute&lt;/code&gt;&lt;/strong&gt; walks down from the root. with every node’s fit already sitting in &lt;code&gt;fits&lt;/code&gt;, each parent takes the space it got and hands out final sizes and positions.&lt;/li&gt;
&lt;/ul&gt;
&lt;svg style=&quot;display: block; margin: 1.5rem 0; font: 13px ui-monospace, monospace; fill: var(--muted)&quot; viewBox=&quot;0 0 650 204&quot; role=&quot;img&quot; aria-label=&quot;a 5-node tree of col containing row (with leaves A and B) and leaf C, stored in pre-order. fit sweeps right to left to fill a fits array [100, 100, 40, 60, 80], then distribute sweeps left to right with screen width 200 to assign final widths [200, 200, 40, 160, 80]&quot;&gt;
  &lt;g style=&quot;stroke: var(--muted); stroke-width: 1.5&quot;&gt;
    &lt;line x1=&quot;103&quot; y1=&quot;64&quot; x2=&quot;60&quot; y2=&quot;94&quot;/&gt;
    &lt;line x1=&quot;103&quot; y1=&quot;64&quot; x2=&quot;156&quot; y2=&quot;94&quot;/&gt;
    &lt;line x1=&quot;60&quot; y1=&quot;120&quot; x2=&quot;34&quot; y2=&quot;150&quot;/&gt;
    &lt;line x1=&quot;60&quot; y1=&quot;120&quot; x2=&quot;88&quot; y2=&quot;150&quot;/&gt;
  &lt;/g&gt;
  &lt;g style=&quot;fill: var(--block)&quot;&gt;
    &lt;rect x=&quot;75&quot; y=&quot;38&quot; width=&quot;56&quot; height=&quot;26&quot;/&gt;
    &lt;rect x=&quot;32&quot; y=&quot;94&quot; width=&quot;56&quot; height=&quot;26&quot;/&gt;
    &lt;rect x=&quot;134&quot; y=&quot;94&quot; width=&quot;44&quot; height=&quot;26&quot;/&gt;
    &lt;rect x=&quot;14&quot; y=&quot;150&quot; width=&quot;40&quot; height=&quot;26&quot;/&gt;
    &lt;rect x=&quot;68&quot; y=&quot;150&quot; width=&quot;40&quot; height=&quot;26&quot;/&gt;
  &lt;/g&gt;
  &lt;g style=&quot;fill: var(--bg)&quot; text-anchor=&quot;middle&quot;&gt;
    &lt;text x=&quot;103&quot; y=&quot;56&quot;&gt;col&lt;/text&gt;
    &lt;text x=&quot;60&quot; y=&quot;112&quot;&gt;row&lt;/text&gt;
    &lt;text x=&quot;156&quot; y=&quot;112&quot;&gt;C&lt;/text&gt;
    &lt;text x=&quot;34&quot; y=&quot;168&quot;&gt;A&lt;/text&gt;
    &lt;text x=&quot;88&quot; y=&quot;168&quot;&gt;B&lt;/text&gt;
  &lt;/g&gt;
  &lt;rect style=&quot;fill: none; stroke: var(--link); stroke-width: 2.5&quot; x=&quot;134&quot; y=&quot;94&quot; width=&quot;44&quot; height=&quot;26&quot; opacity=&quot;0&quot;&gt;
    &lt;animate attributeName=&quot;x&quot; calcMode=&quot;discrete&quot; values=&quot;134;68;14;32;75;75;32&quot; keyTimes=&quot;0;0.12;0.20;0.28;0.36;0.52;0.74&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    &lt;animate attributeName=&quot;y&quot; calcMode=&quot;discrete&quot; values=&quot;94;150;150;94;38;38;94&quot; keyTimes=&quot;0;0.12;0.20;0.28;0.36;0.52;0.74&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    &lt;animate attributeName=&quot;width&quot; calcMode=&quot;discrete&quot; values=&quot;44;40;40;56;56;56;56&quot; keyTimes=&quot;0;0.12;0.20;0.28;0.36;0.52;0.74&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0;1;0&quot; keyTimes=&quot;0;0.04;0.44;0.52;0.86&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
  &lt;/rect&gt;
  &lt;text x=&quot;235&quot; y=&quot;22&quot; style=&quot;fill: var(--link)&quot;&gt;
    &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;1;0;1&quot; keyTimes=&quot;0;0.50;0.98&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    fit ← (bottom up, width)
  &lt;/text&gt;
  &lt;text x=&quot;235&quot; y=&quot;22&quot; style=&quot;fill: var(--link)&quot; opacity=&quot;0&quot;&gt;
    &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.50;0.98&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    distribute → (top down, screen = 200)
  &lt;/text&gt;
  &lt;g style=&quot;fill: none; stroke: var(--muted); stroke-dasharray: 4 4&quot;&gt;
    &lt;rect x=&quot;235&quot; y=&quot;34&quot; width=&quot;402&quot; height=&quot;52&quot;/&gt;
    &lt;rect x=&quot;235&quot; y=&quot;122&quot; width=&quot;402&quot; height=&quot;52&quot;/&gt;
  &lt;/g&gt;
  &lt;g text-anchor=&quot;middle&quot;&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.36;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;239&quot; y=&quot;40&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;276&quot; y=&quot;55&quot;&gt;col&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;276&quot; y=&quot;72&quot;&gt;100&lt;/text&gt;
    &lt;/g&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.28;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;319&quot; y=&quot;40&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;356&quot; y=&quot;55&quot;&gt;row&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;356&quot; y=&quot;72&quot;&gt;100&lt;/text&gt;
    &lt;/g&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.20;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;399&quot; y=&quot;40&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;436&quot; y=&quot;55&quot;&gt;A&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;436&quot; y=&quot;72&quot;&gt;40&lt;/text&gt;
    &lt;/g&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.12;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;479&quot; y=&quot;40&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;516&quot; y=&quot;55&quot;&gt;B&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;516&quot; y=&quot;72&quot;&gt;60&lt;/text&gt;
    &lt;/g&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.04;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;559&quot; y=&quot;40&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;596&quot; y=&quot;55&quot;&gt;C&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;596&quot; y=&quot;72&quot;&gt;80&lt;/text&gt;
    &lt;/g&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.52;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;239&quot; y=&quot;128&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;276&quot; y=&quot;143&quot;&gt;col&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;276&quot; y=&quot;160&quot;&gt;200&lt;/text&gt;
    &lt;/g&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.62;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;319&quot; y=&quot;128&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;356&quot; y=&quot;143&quot;&gt;row&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;356&quot; y=&quot;160&quot;&gt;200&lt;/text&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;559&quot; y=&quot;128&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;596&quot; y=&quot;143&quot;&gt;C&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;596&quot; y=&quot;160&quot;&gt;80&lt;/text&gt;
    &lt;/g&gt;
    &lt;g opacity=&quot;0&quot;&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.74;0.96&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;399&quot; y=&quot;128&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;436&quot; y=&quot;143&quot;&gt;A&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;436&quot; y=&quot;160&quot;&gt;40&lt;/text&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;479&quot; y=&quot;128&quot; width=&quot;74&quot; height=&quot;40&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg); font-size: 11px; opacity: 0.75&quot; x=&quot;516&quot; y=&quot;143&quot;&gt;B&lt;/text&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;516&quot; y=&quot;160&quot;&gt;160&lt;/text&gt;
    &lt;/g&gt;
  &lt;/g&gt;
  &lt;rect style=&quot;fill: none; stroke: var(--link); stroke-width: 2.5&quot; x=&quot;559&quot; y=&quot;40&quot; width=&quot;74&quot; height=&quot;40&quot; opacity=&quot;0&quot;&gt;
    &lt;animate attributeName=&quot;x&quot; calcMode=&quot;discrete&quot; values=&quot;559;479;399;319;239;239;319&quot; keyTimes=&quot;0;0.12;0.20;0.28;0.36;0.52;0.74&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    &lt;animate attributeName=&quot;y&quot; calcMode=&quot;discrete&quot; values=&quot;40;128&quot; keyTimes=&quot;0;0.52&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0;1;0&quot; keyTimes=&quot;0;0.04;0.44;0.52;0.86&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
  &lt;/rect&gt;
  &lt;text x=&quot;235&quot; y=&quot;102&quot;&gt;fits&lt;/text&gt;
  &lt;text x=&quot;235&quot; y=&quot;190&quot;&gt;final width&lt;/text&gt;
&lt;/svg&gt;
&lt;details&gt;
&lt;summary&gt;example: a centering layout&lt;/summary&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Center&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;impl&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Context&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Scalar&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-7&quot;&gt; f32&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Layout&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; for&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Center&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    type&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Item&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; fit&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; LayoutCx&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; C&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; axis&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Axis&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Fit&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-7&quot;&gt;f32&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; axis&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;fold&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Fit&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-7&quot;&gt;ZERO&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt; Fit&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; distribute&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; LayoutCx&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; C&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; axis&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Axis&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; extent&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-7&quot;&gt; f32&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;        for&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; child&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;            let&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; size&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;set_extent&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; axis&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;natural&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;extent&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;            cx&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;set_offset&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;extent&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; size&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; /&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/details&gt;
&lt;p&gt;most retained engines work top down via recursion instead: a parent calls into its children to measure them, then lays them out again once it knows their final bounds. in a nested tree, revisiting children blows up fast, so engines either bolt on a second measurement API just to ask preferred sizes (Flutter, Jetpack Compose) or keep per-node caches to absorb the repeat work (SwiftUI, &lt;a rel=&quot;external&quot; href=&quot;https://github.com/DioxusLabs/taffy&quot;&gt;Taffy&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;that machinery adds up. Taffy retains over 1 KB &lt;strong&gt;per&lt;/strong&gt; node just to solve layout, while blit needs under 100 bytes&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-taffy-1&quot;&gt;&lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fn-taffy&quot;&gt;[3]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;to be fair, blit doesn’t implement all of CSS, and that itself is a feature. CSS has to cram every possible layout rule, and how they all interact, into one giant static set of flags. in blit you pay for what you use, and when your UI needs something unusual, you just write the rules in code.&lt;/p&gt;
&lt;p&gt;it’s easy to assume layout is just inherently this complicated. layout caches, duplicate measurement APIs, kilobytes per node: these aren’t fundamental problems of the universe. they’re artifacts of the constraints we’ve inflicted upon ourselves.&lt;/p&gt;
&lt;h3 id=&quot;animation-is-kinda-just-interpolation&quot;&gt;animation is (kinda) just interpolation&lt;/h3&gt;
&lt;p&gt;to animate a widget moving or resizing, you need to know where it was last frame. in immediate mode, nothing remembers that for you.&lt;/p&gt;
&lt;p&gt;with deferred layout, blit already solves every node’s position and size. by keeping last frame’s around too, it has everything it needs to interpolate between them. you don’t manage animation state, you just tell blit which nodes should animate.&lt;/p&gt;
&lt;p&gt;take &lt;a href=&quot;https://pasttheboonies.com/jots/blit/#deferred-layout&quot;&gt;that row&lt;/a&gt;. suppose we want &lt;code&gt;A&lt;/code&gt; to widen on click, and &lt;code&gt;B&lt;/code&gt; to shrink to make room:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; spring&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Spring&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; width&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;wide &lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt; 120&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; }&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt; 40&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; }&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;motion&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Motion&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;layout&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Rectangle&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-7&quot;&gt;BLACK&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Sizing&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;grow&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;motion&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Motion&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;layout&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-9&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Rectangle&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-7&quot;&gt;GRAY&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;self.wide&lt;/code&gt; is just a bool, and &lt;code&gt;B&lt;/code&gt; is still &lt;code&gt;Sizing::grow()&lt;/code&gt;. layout solves the target rects as usual, and blit springs both nodes there from where they were last frame.&lt;/p&gt;
&lt;svg style=&quot;display: block; margin: 1.5rem 0; font: 14px ui-monospace, monospace; fill: var(--muted)&quot; viewBox=&quot;0 0 650 214&quot; role=&quot;img&quot; aria-label=&quot;A springs from 40 to 120 wide and back while B shrinks and grows to fill the rest&quot;&gt;
&lt;rect style=&quot;fill: none; stroke: var(--muted)&quot; x=&quot;20&quot; y=&quot;24&quot; width=&quot;600&quot; height=&quot;180&quot;/&gt;
&lt;rect style=&quot;fill: var(--block)&quot; x=&quot;20&quot; y=&quot;84&quot; width=&quot;120&quot; height=&quot;60&quot;&gt;&lt;animate attributeName=&quot;width&quot; dur=&quot;3.6s&quot; repeatCount=&quot;indefinite&quot; keyTimes=&quot;0.0;0.0111;0.0222;0.0333;0.0444;0.0556;0.0667;0.0778;0.0889;0.1;0.1111;0.1222;0.1333;0.1444;0.1556;0.1667;0.5;0.5111;0.5222;0.5333;0.5444;0.5556;0.5667;0.5778;0.5889;0.6;0.6111;0.6222;0.6333;0.6444;0.6556;0.6667;1.0&quot; values=&quot;120.0;175.9;265.2;329.8;361.4;370.8;369.4;365.3;361.9;360.2;359.5;359.5;359.8;359.8;360.0;360.0;360.0;304.1;214.8;150.2;118.6;109.2;110.6;114.7;118.1;119.8;120.5;120.5;120.2;120.2;120.0;120.0;120.0&quot;/&gt;&lt;/rect&gt;
&lt;rect style=&quot;fill: var(--link); opacity: 0.5&quot; x=&quot;140&quot; y=&quot;24&quot; width=&quot;12&quot; height=&quot;180&quot;&gt;&lt;animate attributeName=&quot;x&quot; dur=&quot;3.6s&quot; repeatCount=&quot;indefinite&quot; keyTimes=&quot;0.0;0.0111;0.0222;0.0333;0.0444;0.0556;0.0667;0.0778;0.0889;0.1;0.1111;0.1222;0.1333;0.1444;0.1556;0.1667;0.5;0.5111;0.5222;0.5333;0.5444;0.5556;0.5667;0.5778;0.5889;0.6;0.6111;0.6222;0.6333;0.6444;0.6556;0.6667;1.0&quot; values=&quot;140.0;195.9;285.2;349.8;381.4;390.8;389.4;385.3;381.9;380.2;379.5;379.5;379.8;379.8;380.0;380.0;380.0;324.1;234.8;170.2;138.6;129.2;130.6;134.7;138.1;139.8;140.5;140.5;140.2;140.2;140.0;140.0;140.0&quot;/&gt;&lt;/rect&gt;
&lt;rect style=&quot;fill: var(--block-dim)&quot; x=&quot;152&quot; y=&quot;24&quot; width=&quot;468&quot; height=&quot;180&quot;&gt;&lt;animate attributeName=&quot;x&quot; dur=&quot;3.6s&quot; repeatCount=&quot;indefinite&quot; keyTimes=&quot;0.0;0.0111;0.0222;0.0333;0.0444;0.0556;0.0667;0.0778;0.0889;0.1;0.1111;0.1222;0.1333;0.1444;0.1556;0.1667;0.5;0.5111;0.5222;0.5333;0.5444;0.5556;0.5667;0.5778;0.5889;0.6;0.6111;0.6222;0.6333;0.6444;0.6556;0.6667;1.0&quot; values=&quot;152.0;207.9;297.2;361.8;393.4;402.8;401.4;397.3;393.9;392.2;391.5;391.5;391.8;391.8;392.0;392.0;392.0;336.1;246.8;182.2;150.6;141.2;142.6;146.7;150.1;151.8;152.5;152.5;152.2;152.2;152.0;152.0;152.0&quot;/&gt;&lt;animate attributeName=&quot;width&quot; dur=&quot;3.6s&quot; repeatCount=&quot;indefinite&quot; keyTimes=&quot;0.0;0.0111;0.0222;0.0333;0.0444;0.0556;0.0667;0.0778;0.0889;0.1;0.1111;0.1222;0.1333;0.1444;0.1556;0.1667;0.5;0.5111;0.5222;0.5333;0.5444;0.5556;0.5667;0.5778;0.5889;0.6;0.6111;0.6222;0.6333;0.6444;0.6556;0.6667;1.0&quot; values=&quot;468.0;412.1;322.8;258.2;226.6;217.2;218.6;222.7;226.1;227.8;228.5;228.5;228.2;228.2;228.0;228.0;228.0;283.9;373.2;437.8;469.4;478.8;477.4;473.3;469.9;468.2;467.5;467.5;467.8;467.8;468.0;468.0;468.0&quot;/&gt;&lt;/rect&gt;
&lt;text style=&quot;fill: var(--bg)&quot; x=&quot;80&quot; y=&quot;119&quot; text-anchor=&quot;middle&quot;&gt;A&lt;animate attributeName=&quot;x&quot; dur=&quot;3.6s&quot; repeatCount=&quot;indefinite&quot; keyTimes=&quot;0.0;0.0111;0.0222;0.0333;0.0444;0.0556;0.0667;0.0778;0.0889;0.1;0.1111;0.1222;0.1333;0.1444;0.1556;0.1667;0.5;0.5111;0.5222;0.5333;0.5444;0.5556;0.5667;0.5778;0.5889;0.6;0.6111;0.6222;0.6333;0.6444;0.6556;0.6667;1.0&quot; values=&quot;80.0;108.0;152.6;184.9;200.7;205.4;204.7;202.6;201.0;200.1;199.8;199.8;199.9;199.9;200.0;200.0;200.0;172.0;127.4;95.1;79.3;74.6;75.3;77.4;79.0;79.9;80.2;80.2;80.1;80.1;80.0;80.0;80.0&quot;/&gt;&lt;/text&gt;
&lt;text style=&quot;fill: var(--bg)&quot; x=&quot;386&quot; y=&quot;119&quot; text-anchor=&quot;middle&quot;&gt;B&lt;animate attributeName=&quot;x&quot; dur=&quot;3.6s&quot; repeatCount=&quot;indefinite&quot; keyTimes=&quot;0.0;0.0111;0.0222;0.0333;0.0444;0.0556;0.0667;0.0778;0.0889;0.1;0.1111;0.1222;0.1333;0.1444;0.1556;0.1667;0.5;0.5111;0.5222;0.5333;0.5444;0.5556;0.5667;0.5778;0.5889;0.6;0.6111;0.6222;0.6333;0.6444;0.6556;0.6667;1.0&quot; values=&quot;386.0;414.0;458.6;490.9;506.7;511.4;510.7;508.6;507.0;506.1;505.8;505.8;505.9;505.9;506.0;506.0;506.0;478.0;433.4;401.1;385.3;380.6;381.3;383.4;385.0;385.9;386.2;386.2;386.1;386.1;386.0;386.0;386.0&quot;/&gt;&lt;/text&gt;&lt;/svg&gt;
&lt;details&gt;
&lt;summary&gt;how does blit know which node is A?&lt;/summary&gt;
&lt;p&gt;Dear ImGui hashes label strings on an ID stack, so duplicate labels collide unless you disambiguate them:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ImGui&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;delete##1&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ImGui&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;delete##2&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;egui hashes a sequential counter per container, so toggling an &lt;code&gt;if&lt;/code&gt; shifts the IDs of widgets after it unless you scope them:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; show_banner&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;heads up&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;push_id&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;notes&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;text_edit_singleline&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;mut&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; notes&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;blit doesn’t hash&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-hashless-1&quot;&gt;&lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fn-hashless&quot;&gt;[4]&lt;/a&gt;&lt;/sup&gt; at all. each &lt;code&gt;child()&lt;/code&gt; uses rust’s &lt;a rel=&quot;external&quot; href=&quot;https://doc.rust-lang.org/std/attribute.track_caller.html&quot;&gt;&lt;code&gt;#[track_caller]&lt;/code&gt;&lt;/a&gt; to record its source location, and blit walks a cursor alongside the previous frame’s children to match them by call site (and iteration count in a loop). duplicate labels and &lt;code&gt;if&lt;/code&gt; branches just work:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; show_banner&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; col&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;heads up&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;z-l-12 z-d-10&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;when the same widget can be built from a different call site or parent across frames, you pass an explicit key with &lt;code&gt;Ui::child_in(scope, key)&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;h3 id=&quot;bump-arena&quot;&gt;bump arena&lt;/h3&gt;
&lt;p&gt;retained-mode frameworks allocate each node individually on the heap because any widget might live for two frames or two hours. they can’t assume anything about when that memory dies.&lt;/p&gt;
&lt;p&gt;in blit, everything built for a frame dies together. frame state sits in a few arrays, and when the frame ends their lengths just reset to zero.&lt;/p&gt;
&lt;p&gt;for things that don’t have a fixed type, like layouts and paint closures, blit uses a bump arena. it’s a single byte array that packs values of any type back to back, addressed by &lt;code&gt;u32&lt;/code&gt; offsets.&lt;/p&gt;
&lt;p&gt;after the first few frames settle, building the UI doesn’t touch the system allocator at all, and everything the layout and paint passes need sits side by side in memory.&lt;/p&gt;
&lt;p&gt;here’s the toggle demo from earlier in blit:&lt;/p&gt;
&lt;svg style=&quot;display: block; margin: 1.5rem 0; font: 13px ui-monospace, monospace; fill: var(--muted)&quot; viewBox=&quot;0 0 650 178&quot; role=&quot;img&quot; aria-label=&quot;the toggle code runs line by line and each line pushes its node and its layout or paint into two packed arrays. on the next frame show_details is false, the if body is skipped, and the arrays come out shorter&quot;&gt;
  &lt;rect style=&quot;fill: var(--link); opacity: 0.18&quot; x=&quot;10&quot; y=&quot;33&quot; width=&quot;340&quot; height=&quot;21&quot;&gt;
    &lt;animate attributeName=&quot;y&quot; calcMode=&quot;discrete&quot; values=&quot;33;55;77;99;121;33;55;77;121&quot; keyTimes=&quot;0;0.12;0.2;0.28;0.36;0.5;0.62;0.7;0.78&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;0.18;0;0.18;0&quot; keyTimes=&quot;0;0.04;0.42;0.54;0.86&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
  &lt;/rect&gt;
  &lt;text x=&quot;16&quot; y=&quot;20&quot;&gt;
    &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;1;0;1&quot; keyTimes=&quot;0;0.48;0.98&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    // show_details: true
  &lt;/text&gt;
  &lt;text x=&quot;16&quot; y=&quot;20&quot; opacity=&quot;0&quot;&gt;
    &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.48;0.98&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
    // show_details: false
  &lt;/text&gt;
  &lt;g style=&quot;fill: var(--fg); white-space: pre&quot; xml:space=&quot;preserve&quot;&gt;
    &lt;text x=&quot;16&quot; y=&quot;48&quot;&gt;let mut row = ui.layout(flex::row());&lt;/text&gt;
    &lt;text x=&quot;16&quot; y=&quot;70&quot;&gt;row.child().build(Button::new(&quot;..&quot;));&lt;/text&gt;
    &lt;text x=&quot;16&quot; y=&quot;92&quot;&gt;if self.show_details {&lt;/text&gt;
    &lt;text x=&quot;47&quot; y=&quot;114&quot;&gt;row.child().insert(Text::new(&quot;..&quot;));&lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;1;0.35;1&quot; keyTimes=&quot;0;0.48;0.98&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;&lt;/text&gt;
    &lt;text x=&quot;16&quot; y=&quot;136&quot;&gt;}&lt;/text&gt;
  &lt;/g&gt;
  &lt;g style=&quot;fill: none; stroke: var(--muted); stroke-dasharray: 4 4&quot;&gt;
    &lt;rect x=&quot;390&quot; y=&quot;30&quot; width=&quot;230&quot; height=&quot;44&quot;/&gt;
    &lt;rect x=&quot;390&quot; y=&quot;104&quot; width=&quot;230&quot; height=&quot;44&quot;/&gt;
  &lt;/g&gt;
  &lt;g text-anchor=&quot;middle&quot;&gt;
    &lt;g&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0;1;0&quot; keyTimes=&quot;0;0.04;0.44;0.54;0.94&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;396&quot; y=&quot;36&quot; width=&quot;70&quot; height=&quot;32&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;431&quot; y=&quot;57&quot;&gt;app&lt;/text&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;396&quot; y=&quot;110&quot; width=&quot;70&quot; height=&quot;32&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;431&quot; y=&quot;131&quot;&gt;row&lt;/text&gt;
    &lt;/g&gt;
    &lt;g&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0;1;0&quot; keyTimes=&quot;0;0.12;0.44;0.62;0.94&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;470&quot; y=&quot;36&quot; width=&quot;70&quot; height=&quot;32&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;505&quot; y=&quot;57&quot;&gt;button&lt;/text&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;470&quot; y=&quot;110&quot; width=&quot;70&quot; height=&quot;32&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;505&quot; y=&quot;131&quot;&gt;paint&lt;/text&gt;
    &lt;/g&gt;
    &lt;g&gt;
      &lt;animate attributeName=&quot;opacity&quot; calcMode=&quot;discrete&quot; values=&quot;0;1;0&quot; keyTimes=&quot;0;0.28;0.44&quot; dur=&quot;10s&quot; repeatCount=&quot;indefinite&quot;/&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;544&quot; y=&quot;36&quot; width=&quot;70&quot; height=&quot;32&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;579&quot; y=&quot;57&quot;&gt;text&lt;/text&gt;
      &lt;rect style=&quot;fill: var(--block)&quot; x=&quot;544&quot; y=&quot;110&quot; width=&quot;70&quot; height=&quot;32&quot;/&gt;
      &lt;text style=&quot;fill: var(--bg)&quot; x=&quot;579&quot; y=&quot;131&quot;&gt;paint&lt;/text&gt;
    &lt;/g&gt;
  &lt;/g&gt;
  &lt;text x=&quot;390&quot; y=&quot;94&quot;&gt;nodes&lt;/text&gt;
  &lt;text x=&quot;390&quot; y=&quot;168&quot;&gt;bump&lt;/text&gt;
&lt;/svg&gt;
&lt;h3 id=&quot;the-c-context-generic&quot;&gt;the &lt;code&gt;C&lt;/code&gt; context generic&lt;/h3&gt;
&lt;p&gt;deep inside a UI, widgets often need access to ambient things like a theme or a renderer. normally you either pass those arguments down through every function along the way (prop drilling), or stash them in globals and runtime context lookups.&lt;/p&gt;
&lt;p&gt;instead, everything in blit is generic over a context &lt;code&gt;C&lt;/code&gt;, which acts like a typed global threaded through the entire frame. in your own app, you just use your concrete context struct directly and read off &lt;code&gt;ui.context()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;when you want a widget to work across different contexts, bound it with a trait:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;trait&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; HasTheme&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; theme&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;Theme&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;impl&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Context&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; HasTheme&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Widget&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; for&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Button&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    type&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Response&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-7&quot;&gt; bool&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; mut&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; Ui&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-11&quot;&gt; C&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-7&quot;&gt; bool&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;        let&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; theme&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;theme&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;        let&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; press&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;interact&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;interact&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;press&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt;        let&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; background&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; press&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;active &lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; theme&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;active &lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-6&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt; {&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt; theme&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;surface &lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Rectangle&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-3&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        ui&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-9&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-b&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-8&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;label&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-11&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3&quot;&gt;        press&lt;/span&gt;&lt;span class=&quot;z-d-9&quot;&gt;.&lt;/span&gt;&lt;span&gt;clicked&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;you can test &lt;code&gt;Button&lt;/code&gt; by passing a tiny &lt;code&gt;Test(Theme)&lt;/code&gt; struct with no window needed. blit’s own widgets work the same way, which is how the same layouts and widgets run on both a terminal and a GPU.&lt;/p&gt;
&lt;h2 id=&quot;performance&quot;&gt;performance&lt;/h2&gt;
&lt;p&gt;blit started as a software rendered UI framework for KeyOS, &lt;a rel=&quot;external&quot; href=&quot;https://en.wikipedia.org/wiki/Bit_blit&quot;&gt;hence the name&lt;/a&gt;. on KeyOS, every app renders directly into a framebuffer and hands it to our compositor, which puts it on an LCDC hardware layer at the next vsync. most UI frameworks lean heavily on the GPU. if they support software rendering at all, it’s basically a GPU triangle pipeline emulated on the CPU (not very fast!). in blit, software rendering is a first class use case. moving KeyOS from Slint to blit took us from 30 (best case) to 60 fps, and cut build times and binary sizes by 60-70%.&lt;/p&gt;
&lt;p&gt;for the mandatory vanity benchmarks, I built &lt;a rel=&quot;external&quot; href=&quot;https://github.com/nicoburniske/blit-demo&quot;&gt;a dashboard&lt;/a&gt; running on both the terminal and desktop backends:&lt;/p&gt;
&lt;figure class=&quot;bleed&quot;&gt;
  &lt;div class=&quot;pair&quot;&gt;
    &lt;video src=&quot;blit-dashboard-tui.mp4&quot; poster=&quot;blit-dashboard-tui.png&quot; autoplay loop muted playsinline preload=&quot;auto&quot;&gt;&lt;/video&gt;
    &lt;video src=&quot;blit-dashboard-gui.mp4&quot; poster=&quot;blit-dashboard-5k.png&quot; autoplay loop muted playsinline preload=&quot;auto&quot;&gt;&lt;/video&gt;
  &lt;/div&gt;
  &lt;figcaption class=&quot;split&quot;&gt;&lt;span&gt;tui @ 230×70&lt;/span&gt;&lt;span&gt;gui @ 5K&lt;/span&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;here’s the frame time breakdown&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-machine-2&quot;&gt;&lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fn-machine&quot;&gt;[2]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;h3 id=&quot;build-layout&quot;&gt;build &amp;amp; layout&lt;/h3&gt;
&lt;p&gt;building and laying out the dashboard takes &lt;strong&gt;~50 µs&lt;/strong&gt; with &lt;strong&gt;zero&lt;/strong&gt; allocations.&lt;/p&gt;
&lt;h3 id=&quot;the-renderers&quot;&gt;the renderers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;the &lt;strong&gt;software&lt;/strong&gt; renderer is an aggressively SIMD’d scanline renderer that skips anything hidden behind an opaque shape. a full 5K repaint takes &lt;strong&gt;~6 ms on a single thread&lt;/strong&gt;. if only part of the screen changes a frame takes &lt;strong&gt;~2 ms&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;the &lt;strong&gt;GPU&lt;/strong&gt; renderer uses wgpu, and usually draws the whole frame in one instanced draw call. well under &lt;strong&gt;1 ms&lt;/strong&gt; at 5K&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;the &lt;strong&gt;terminal&lt;/strong&gt; renderer repaints 230×70 in &lt;strong&gt;~280 µs&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;blit-is-for-you&quot;&gt;blit is for you&lt;/h2&gt;
&lt;p&gt;somewhere along the way, UI got big. big runtimes, big dependency trees, big DSLs, all built to serve everyone at once.&lt;/p&gt;
&lt;p&gt;blit is small, FAST, and modular on purpose. it doesn’t treat you like a child or hand you someone else’s compromises.&lt;/p&gt;
&lt;p&gt;it’s still experimental and rough around the edges, but it already runs on Wayland, macOS, terminals, KeyOS, and even a &lt;a rel=&quot;external&quot; href=&quot;https://github.com/nicoburniske/comically/tree/main/reader&quot;&gt;Kindle&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
  &lt;video src=&quot;kindle-demo.mp4&quot; poster=&quot;kindle-demo.jpg&quot; controls muted playsinline preload=&quot;metadata&quot;&gt;&lt;/video&gt;
  &lt;figcaption&gt;manga reader running on a Kindle&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https://github.com/nicoburniske/blit&quot;&gt;come check it out&lt;/a&gt;&lt;/p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-dioxus&quot;&gt;
&lt;p&gt;slint has its own language, compiler, and build step. dioxus is plain rust so it’s simpler to compare against. &lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fr-dioxus-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-machine&quot;&gt;
&lt;p&gt;rough numbers from my machine: Ryzen 9 7900 at 5.4 GHz, Radeon RX 9070, NixOS. ymmv &lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fr-machine-1&quot;&gt;↩&lt;/a&gt; &lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fr-machine-2&quot;&gt;↩2&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-taffy&quot;&gt;
&lt;p&gt;measured on a 1,000-node flex tree: &lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fr-taffy-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Taffy v0.16.1&lt;/strong&gt;: &lt;strong&gt;~1.28 KB/node&lt;/strong&gt; (&lt;a rel=&quot;external&quot; href=&quot;https://github.com/DioxusLabs/taffy/blob/v0.16.1/src/tree/taffy_tree.rs#L97-L121&quot;&gt;&lt;code&gt;NodeData&lt;/code&gt;&lt;/a&gt; holds a 560 B &lt;code&gt;Style&lt;/code&gt;, 408 B &lt;code&gt;Cache&lt;/code&gt;, two 92 B &lt;code&gt;Layout&lt;/code&gt;s, plus tree storage).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;blit&lt;/strong&gt;: &lt;strong&gt;~98 B/node&lt;/strong&gt; for layout state, or &lt;strong&gt;~253 B/node&lt;/strong&gt; for the full double-buffered &lt;code&gt;Tree&lt;/code&gt; (previous-frame state, identity, hit testing, paint).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-hashless&quot;&gt;
&lt;p&gt;inspired by &lt;a rel=&quot;external&quot; href=&quot;https://www.youtube.com/watch?v=h4GQfQmNi_4&quot;&gt;hashless imgui&lt;/a&gt; talk. &lt;a href=&quot;https://pasttheboonies.com/jots/blit/#fr-hashless-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
        
    </entry>
</feed>
