blinc_canvas_kit
Part of the Blinc UI Framework
This crate is a component of Blinc, a GPU-accelerated UI framework for Rust. For full documentation and guides, visit the Blinc documentation.
Interactive canvas toolkit for 2D editors, 3D scene viewers, and node graphs — pan, zoom, spatial indexing, multi-select, PBR mesh rendering, orbit camera, and more.
Overview
blinc_canvas_kit provides two main toolkits:
CanvasKit — 2D infinite canvas
Everything needed to build interactive infinite canvas applications:
- Viewport Management: Pan (with momentum), zoom (scroll + pinch), coordinate conversion between screen-space and content-space
- Spatial Indexing: Uniform-grid spatial hash for O(1) hit testing and fast range queries
- Multi-Select: Shift+click to add, Cmd/Ctrl+click to toggle, with selection change callbacks
- Marquee Selection: Box-select via tool mode or Shift+drag
- Snap-to-Grid: Round content-space positions to configurable grid spacing
- Background Patterns: Infinite dot grid, line grid, and crosshatch with zoom-adaptive density
- Viewport Culling: Skip rendering off-screen elements
- Hit Regions: Register interactive bounding boxes with click/hover/drag callbacks
SceneKit3D — 3D scene viewer (mini Three.js)
A Three.js-inspired API for 3D mesh rendering within Blinc's canvas element:
- Orbit Camera: Drag to orbit, scroll to zoom, with momentum deceleration
- PBR Mesh Rendering: Cook-Torrance BRDF with per-texel metallic/roughness/emissive/AO textures
- IBL Environment: Procedural studio lighting cubemap with HDR area lights for realistic reflections
- HDR + Tonemapping: Rgba16Float intermediate with ACES filmic tonemap
- Bloom: Threshold extraction + Kawase blur post-process
- Infinity Grid: Anti-aliased ground-plane grid via
CustomRenderPassat theScene3Dstage - Geometry Primitives:
Geometry::cube,sphere,plane,cylinder,toruswith normals + UVs - Material Builder:
MaterialBuilder::standard().color(c).metallic(m).roughness(r) - Scene Management:
kit.add(geometry, material) → MeshHandle, transform updates, auto-rendering
Quick Start — 2D Canvas
use *;
let mut kit = new
.with_background
.with_snap;
kit.on_element_click;
kit.element
Quick Start — 3D Scene
use *;
use ;
let kit = new
.with_camera
.with_light
.with_grid;
// Add primitives with materials
let cube = kit.add;
kit.set_position;
// Self-rendering — no draw closure needed
kit.element_auto
Features
Tool Modes (2D)
kit.set_tool; // Background drag pans
kit.set_tool; // Background drag draws marquee
Selection (2D)
let sel = kit.selection;
if kit.is_selected
kit.set_selection;
Scene Objects (3D)
// Add from geometry + material
let sphere = kit.add;
// Add from loaded mesh data (e.g. glTF)
let helmet = kit.add_mesh;
// Transform
kit.set_position;
kit.set_rotation;
kit.set_scale;
kit.set_visible;
Orbit Camera (3D)
let kit = new
.with_camera
.with_drag_sensitivity
.with_zoom_sensitivity
.with_momentum_decay;
Architecture
| Module | Purpose |
|---|---|
viewport |
Pan/zoom state, coordinate conversion, visibility testing |
pan |
Momentum panning with EMA velocity tracking |
zoom |
Scroll and pinch zoom handlers |
spatial |
Uniform-grid spatial hash for hit testing and range queries |
selection |
Multi-select state, marquee drag, tool modes |
snap |
Grid snapping for content-space coordinates |
background |
Infinite viewport-aware pattern rendering |
hit |
Hit region types and event structs |
scene3d |
SceneKit3D + OrbitCamera + environment cubemap generation |
geometry |
Primitive geometry generators (cube, sphere, plane, cylinder, torus, grid) |
material |
MaterialBuilder for ergonomic PBR material creation |
grid_pass |
Infinity grid as CustomRenderPass at Scene3D stage |
All state persists across UI rebuilds via BlincContextState keyed storage.