Skip to content

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)
  1. Declarative Panel (blendcss.Panel): Generates a standard bpy.types.Panel subclass so Blender shows your panel in the N-Panel sidebar, handles collapsing/expanding, and reserves the exact vertical height your content needs.
  2. 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.
  3. GPU Rendering: Draws the geometry onto Blender's UI region using Blender's gpu module with custom shaders for SSAA (supersampling anti-aliasing), gradients, blurred shadows, backdrop blur, and rounded corner clipping.
  4. 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 tells GpuCanvas.draw_placeholder(layout) how many vertical pixels to reserve inside the native bpy.types.Panel.
  • Scroll and clip synchronization: When the user scrolls the N-Panel or collapses a panel above yours, GpuManager reads 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, UICssDocument feeds pointer coordinates into RmlUi and maps CSS cursor properties (such as pointer or ew-resize) to Blender's native window cursor.
  • Keyboard capture during inline editing: When the user clicks a bound ui.number field to type a number or math expression, GpuManager captures keystrokes exclusively for that field so pressing X, G, or R edits the number instead of triggering Blender viewport shortcuts. Pressing Enter, 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_id share a single GpuManager and modal operator ({addon_id}.gpu_panel_handler).
  • Unregistering all panels for one addon_id tears down only that addon's manager and GPU resources without affecting other addons.

Released under the GNU GPL v3.0 License.