How blendcss Works
This page explains how blendcss embeds an HTML/CSS interface inside Blender's native N-Panel sidebar without fighting Blender's layout system, scrolling, or other addons.
High-level pipeline
Every blendcss.Panel connects four lightweight layers:
text
Your Panel (Python + CSS)
│
▼
UICssDocument (RmlUi 6.4 layout & DOM)
│ outputs batched vertices + FreeType/SVG/image textures
▼
Blender GPU Shaders (SSAA offscreen resolve + custom effects)
│ clipped & anchored to exact N-Panel bounds
▼
GpuManager & GpuCanvas (modal input routing + multi-addon isolation)- Declarative Panel (
blendcss.Panel): Generates a standardbpy.types.Panelsubclass so Blender shows your panel in the N-Panel sidebar, handles collapsing/expanding, and reserves the exact vertical height your content needs. - HTML/CSS Layout (
UICssDocument+ RmlUi): Parses your HTML/CSS, computes Flexbox layout, rasterizes FreeType text and LunaSVG icons, and outputs flat triangle geometry directly to Python. - GPU Rendering: Draws the geometry onto Blender's
UIregion using Blender'sgpumodule with custom shaders for SSAA (supersampling anti-aliasing), gradients, blurred shadows, backdrop blur, and rounded corner clipping. - Bounds Alignment & Input (
GpuManager+GpuCanvas): Uses an in-process native memory inspector (my_engine) to read Blender's live panel bounds and scroll offset, keeping your GPU UI locked pixel-for-pixel to the N-Panel as you scroll or resize the sidebar.
How panel height and scrolling stay in sync
Blender's native N-Panel does not know how tall a custom GPU widget is on its own. blendcss solves this in two steps:
- Height reservation:
UICssDocument.get_total_height()measures the rendered DOM content height and tellsGpuCanvas.draw_placeholder(layout)how many vertical pixels to reserve inside the nativebpy.types.Panel. - Scroll and clip synchronization: When the user scrolls the N-Panel or collapses a panel above yours,
GpuManagerreads the updated panel origin and visible clip rectangle so your UI moves smoothly and never bleeds outside the sidebar or over panel headers.
Event routing and keyboard isolation
GpuManager runs a lightweight background modal operator ({addon_id}.gpu_panel_handler) that observes pointer and keyboard events only when relevant:
- Pass-through by default: When the mouse is outside your panel (or over a collapsed panel), every event passes straight through to Blender with zero interference.
- Hover and cursor sync: When hovering over your panel,
UICssDocumentfeeds pointer coordinates into RmlUi and maps CSScursorproperties (such aspointerorew-resize) to Blender's native window cursor. - Keyboard capture during inline editing: When the user clicks a bound
ui.numberfield to type a number or math expression,GpuManagercaptures keystrokes exclusively for that field so pressingX,G, orRedits the number instead of triggering Blender viewport shortcuts. PressingEnter,Escape, or clicking outside commits/cancels the edit and immediately restores normal Blender shortcuts.
Multi-addon isolation
If two different addons both vendor blendcss/, they remain completely isolated:
- Each addon sets its own
addon_id(for example"sculpt_kit"vs"uv_packer"). - All panels sharing an
addon_idshare a singleGpuManagerand modal operator ({addon_id}.gpu_panel_handler). - Unregistering all panels for one
addon_idtears down only that addon's manager and GPU resources without affecting other addons.