Skip to main content

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

ApproachUse caseCrate
Raw APIFull control over render loop, font loading, event dispatchwgpu-html
Winit harnessBatteries-included window appwgpu-html-winit
egui backendEmbed in egui/eframewgpu-html-egui

Core Facade

// Cargo.toml
[dependencies]
wgpu-html = "0.1"

The facade re-exports:

  • wgpu_html_layout as layout
  • wgpu_html_models as models
  • wgpu_html_parser as parser
  • wgpu_html_renderer as renderer
  • wgpu_html_style as style
  • wgpu_html_text as text
  • wgpu_html_tree as tree
  • wgpu_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-cascade
  • PartialCascade — 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