Repository navigation
CanvasKit Interactive Canvases
When a sketch needs hit-testing, pointer / keyboard events, pan, or zoom, pair it with CanvasKit. Register hit regions by ID inside draw, install callbacks once on the kit itself, and wire pan/zoom automatically.
use blinc_canvas_kit::prelude::*;
struct Scene {
kit: CanvasKit,
hovered: Option<String>,
}
impl Sketch for Scene {
fn setup(&mut self, _ctx: &mut SketchContext<'_>) {
self.kit.on_element_click(|ev| {
println!("clicked region: {}", ev.id);
});
// Note: hover callbacks run on pointer enter / leave. Persist the
// hovered id into sketch state to drive per-frame highlight logic.
let hovered = /* reference-counted handle back into sketch state */;
self.kit.on_element_hover(move |ev| {
// update `hovered` here
});
}
fn draw(&mut self, ctx: &mut SketchContext<'_>, _t: f32, _dt: f32) {
// Register hit regions each frame (IDs flow into the callbacks).
self.kit.hit_rect("box-a", Rect::new(50.0, 50.0, 100.0, 100.0));
self.kit.hit_rect("box-b", Rect::new(200.0, 50.0, 100.0, 100.0));
// Draw — pick color based on whatever the hover callback stashed.
}
}All installed on the CanvasKit once (typically in setup or at construction):
| Callback | Fires on |
|---|---|
on_element_click(cb) |
Click on a hit region |
on_element_hover(cb) |
Enter / leave a hit region |
on_element_drag(cb) |
Drag a hit region |
on_element_drag_end(cb) |
Drag release |
on_selection_change(cb) |
Multi-select / marquee changes |
Each callback receives a CanvasEvent carrying the region id, the content-space pointer position, and the triggering EventContext.
CanvasKit wires the following automatically once it's in a sketch:
- Pan — drag on empty background
- Zoom — scroll wheel (content-space)
- Marquee select — drag from empty background with shift / modifier
-
Grid snap — configurable via
kit.snap_rect(rect)/kit.snap_point(p)
Tune sensitivity via the builder methods before mounting:
let kit = CanvasKit::new("scene")
.with_drag_sensitivity(1.0)
.with_zoom_sensitivity(0.1)
.with_momentum_decay(0.92);hit_rect and hit_test operate on content-space coordinates (pre-pan, pre-zoom). The kit transforms pointer events and render bounds into content space before dispatching — you author as if the canvas were infinite and at 1:1 zoom. Use kit.is_visible(rect) to cull content-space rects against the current viewport before drawing expensive primitives.
See the Canvas Kit Interactive example for a complete walkthrough with pan, zoom, hover feedback, drag, marquee select, and a HUD overlay.
To pipe every event the kit receives (pointer, scroll, key) into a single callback — useful for bridging into blinc_input::InputState::record or custom routing — attach .on_canvas_events(|e| ...) to the Div returned by sketch():
use blinc_canvas_kit::sketch::SketchEvents;
sketch("scene", Scene { kit: CanvasKit::new("scene") })
.on_canvas_events(|ev| input.record(ev))Getting Started
Migrating
Mobile Development
Example Gallery
- Example Gallery
- Canvas Element
- Canvas Kit Interactive
- Carousel Demo - Selector API Showcase
- Chrome-Style Tabs
- blinc_cn Components
- Run with
cargo run -p blinc_app_examples --features cn --example cn_pickers_demo. - Code Element
- Complex SVG
- CSS Debug
- CSS Visual Features
- Layer Effects
- Emoji and HTML Entities
- @flow Shader
- Fluid Surface
- Skeleton animation with glTF +
blinc_canvas_kit. - Gpu Pass Demo
- Image CSS Styling
- Image Layer Test
- Keyframe Animation Canvas
- Markdown Editor
- 3D Mesh Demo — renders the Khronos glTF
DamagedHelmetsample model - Motion Demo
- Music Player Glass Card
- Node-editor demo — pre-wired graph with three node types, typed
- Notch Menu Bar
- Overflow Fade
- Overlay System
- Pointer Query
- Rich Text Element
- Rich Text Editor
- Scroll Container
- Semantic @flow
- Sortable
- Stateful API + Signal-bound modifiers demo.
- End-to-end 3D demo wiring Blinc's SceneKit3D renderer up to
- Unified Styling API
- SVG Animation
- Table Builder
- Tabler Icons
- Minimal text positioning test
- Text Input Widgets
- KHR_texture_transform
- Theme System
- Timeline Animation
- Typography
- Wet Glass
- Windowed Application
Web Development
Core Concepts
- Elements & Layout
- Styling & Materials
- CSS Styling
- Theming
- Event Handling
- Accessibility
- State Management
- Lists & Conditional Content
- Element Refs
Animation
Components
Component Library (blinc_cn)
- Overview
- Button
- Card
- Icons
- Typography
- Dialog
- Form Components
- Date, Time and Colour Pickers
- Rich Text Editor
- Code Editor
- Navigation
- Feedback
- Layout
- Data Display
Widgets
- Buttons & Inputs
- Text & Rich Text
- Code Editor
- Scroll Containers
- Virtualized List
- Canvas Drawing
- Gestures
- Notched Surfaces
- Images & SVG
- Audio & Video
- Markdown Rendering
Canvas Kit
Advanced
- Routing & Navigation
- Multi-Window
- System Integration
- Element Query API
- Overlay System
- Custom State Machines
- Pointer Query
- Performance Tips
- Flow Shaders
- 3D Rendering
- Custom GPU Passes
- Hot reloading
Architecture
Contributing