Choosing an Authoring Mode
blendcss.Panel supports three ways to describe your panel UI. All three share the same CSS engine, theme sync, bindings, and GPU renderer — the difference is how you write and update the UI structure.
Quick comparison
| Mode | Entry point | Best for | How updates work |
|---|---|---|---|
| Immediate-mode Python | draw(self, ui, context) | Dynamic panels with tabs, conditionals, and loops (closest to bpy.types.Panel.draw) | Diffs structure on redraws; patches changed text/classes/styles in place |
| Retained-mode Python | build(self, ui) + on_sync(self, context) | Static layouts where you update specific labels, visibility, or classes | Builds DOM once on mount; you mutate saved UINode handles in on_sync() |
| Raw HTML & CSS templates | html_file / html + on_mount() + @blendcss.on | Complex custom layouts, web-designer workflows, and disk hot-reloading | Loads HTML once; you bind elements in on_mount() and mutate via doc["id"] |
1. Immediate-mode draw(self, ui, context)
This is the recommended default for most Blender addons.
If you have written a standard bpy.types.Panel, draw(self, ui, context) feels immediately natural: you can use plain Python if/elif branches (for tabs or selection checks) and for loops (for lists of modifiers, objects, or axes).
How blendcss keeps draw() fast
Rebuilding an entire HTML document on every redraw would be slow and would break active drags. Instead, blendcss uses a two-tier reconciliation step on every redraw:
- Fast path (structure unchanged):
blendcsscomputes a lightweightstructure_signature()of the element tags, IDs, bindings, and events. If the structure matches the previous frame, it patches only changed text, classes, inline styles, attributes, visibility, and binding targets in place — without reloading the RmlUi document. - Structural reload (structure changed): If a branch changed (for example, the user clicked a different tab or selected an object when none was selected),
blendcssswaps in the new HTML, re-attaches bindings, and updates the layout height automatically. - Drag protection: While the user is actively scrubbing or typing in a bound numeric field,
draw()reconciliation pauses so drags never stutter or reset.
Note on _RestrictContext during register()
During addon registration, Blender passes a restricted context without scene or active_object. blendcss automatically defers the first draw(self, ui, context) call until Blender's first real panel redraw.
2. Retained-mode build(self, ui) + on_sync(self, context)
Choose build(self, ui) when your panel layout is mostly fixed and you want explicit control over every DOM mutation.
build(self, ui)runs once on mount (and again if you callself.reload()).- You store references to elements you plan to update (
self.title = ui.label(...),self.section = ui.col()). - In
on_sync(self, context), you updateself.title.text,self.section.visible, or CSS classes directly. Because every property setter is dirty-checked, unchanged values cost almost nothing.
3. Raw HTML & CSS templates (html_file / html)
Choose raw HTML/CSS templates when:
- You want to design your UI in standalone
.htmland.cssfiles with full editor syntax highlighting. - You want a designer to iterate on markup and styles using
self.reload()without touching Python code. - You have custom markup structures that do not map to
UIBuilderwidgets.
In this mode, wire clicks and events with @blendcss.on("elem_id", "click"), attach reactive bindings in on_mount(self, doc), and update dynamic elements with self.doc["elem_id"].
Precedence rules
If a Panel subclass defines multiple content sources, blendcss resolves them in this order:
html_file(always takes priority if set)draw(self, ui, context)build(self, ui)html/build_html()
In all modes, on_mount(self, doc), on_sync(self, context), on_destroy(), css / css_file, and sync_theme work the same way.