Skip to content

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 ​

ModeEntry pointBest forHow updates work
Immediate-mode Pythondraw(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 Pythonbuild(self, ui) + on_sync(self, context)Static layouts where you update specific labels, visibility, or classesBuilds DOM once on mount; you mutate saved UINode handles in on_sync()
Raw HTML & CSS templateshtml_file / html + on_mount() + @blendcss.onComplex custom layouts, web-designer workflows, and disk hot-reloadingLoads 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:

  1. Fast path (structure unchanged): blendcss computes a lightweight structure_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.
  2. Structural reload (structure changed): If a branch changed (for example, the user clicked a different tab or selected an object when none was selected), blendcss swaps in the new HTML, re-attaches bindings, and updates the layout height automatically.
  3. 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 call self.reload()).
  • You store references to elements you plan to update (self.title = ui.label(...), self.section = ui.col()).
  • In on_sync(self, context), you update self.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 .html and .css files 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 UIBuilder widgets.

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:

  1. html_file (always takes priority if set)
  2. draw(self, ui, context)
  3. build(self, ui)
  4. 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.

Released under the GNU GPL v3.0 License.