Rust Integration Overview
The wgpu-html crate is the top-level facade. It re-exports all sub-crates and provides convenient pipeline functions so you only need one dependency.
Integration Approaches
| Approach | Use case | Crate |
|---|---|---|
| Raw API | Full control over render loop, font loading, event dispatch | wgpu-html |
| Winit harness | Batteries-included window app | wgpu-html-winit |
| egui backend | Embed in egui/eframe | wgpu-html-egui |
Core Facade
// Cargo.toml
[dependencies]
wgpu-html = "0.1"
The facade re-exports:
wgpu_html_layoutaslayoutwgpu_html_modelsasmodelswgpu_html_parserasparserwgpu_html_rendererasrendererwgpu_html_styleasstylewgpu_html_textastextwgpu_html_treeastreewgpu_html::paint,wgpu_html::interactivity,wgpu_html::scroll
Main API
One-Shot Pipeline
pub fn paint_tree_returning_layout(
tree: &Tree,
text_ctx: &mut TextContext,
image_cache: &mut ImageCache,
viewport_w: f32, viewport_h: f32, scale: f32,
) -> (DisplayList, Option<LayoutBox>)
Cascade → layout → paint in one call. Returns a finalized DisplayList ready for the renderer, plus the LayoutBox for hit-testing.
Profiled Variant
pub fn paint_tree_returning_layout_profiled(
tree: &Tree,
text_ctx: &mut TextContext,
image_cache: &mut ImageCache,
viewport_w: f32, viewport_h: f32, scale: f32,
) -> (DisplayList, Option<LayoutBox>, PipelineTimings)
Returns PipelineTimings { cascade_ms, layout_ms, paint_ms }.
Separate Layout + Paint
pub fn compute_layout(
tree: &Tree,
text_ctx: &mut TextContext,
image_cache: &mut ImageCache,
viewport_w: f32, viewport_h: f32, scale: f32,
) -> Option<LayoutBox>
pub fn paint_layout(root: &LayoutBox, list: &mut DisplayList);
Use when you need the layout for hit-testing between frames without repainting.
Cached Pipeline
pub fn paint_tree_cached<'c>(
tree: &Tree,
text_ctx: &mut TextContext,
image_cache: &mut ImageCache,
viewport_w: f32, viewport_h: f32, scale: f32,
cache: &'c mut PipelineCache,
) -> (DisplayList, Option<&'c LayoutBox>, PipelineTimings)
Automatically skips cascade + layout when inputs haven't changed (viewport size, tree generation, font generation, interaction state). Three action levels:
FullPipeline— DOM/viewport/fonts changed, full re-cascadePartialCascade— only pseudo-class state changed (hover/active/focus)RepaintOnly— only scroll/selection/caret changed
Screenshot APIs
renderer.capture_to(&list, width, height, "frame.png")?;
renderer.capture_rect_to(&list, region, "region.png")?;
wgpu_html::screenshot_node_to(&tree, &mut text_ctx, &mut image_cache, &mut renderer, &path, ...)?;
Sub-Pages
- Integration Guide — step-by-step from scratch
- Winit Harness — batteries-included
WgpuHtmlWindow - egui Backend — embedding in egui/eframe
- Screenshots — capture to PNG
- Profiling — performance measurement