Skip to main content

Crate blockworx_canvas2d

Crate blockworx_canvas2d 

Source
Expand description

The web backend: the only crate that knows both the paint vocabulary and the DOM.

Everything a drawing is made of — the Renderer and Canvas traits, the palette, the theme, the ground and its grid rule, the recorder that turns a frame into DrawOps — lives in [blockworx_paint] over the coordinates in blockworx_geom, and the text engine that lays a run out lives in blockworx_text. Here those become Canvas2D calls: replay() draws a display list onto a CanvasRenderingContext2d, paint_ground() rules what lies under it, Glyphs is the text engine the kernel is called with and the ink its glyphs are filled from, Images holds the artwork a hand-off delivered, input turns DOM events into the kernel’s own, and download/clipboard_write are the two hand-offs a backend can perform without a shell around it.

The dependency goes one way, as it does for the egui backend. This crate names the document (for an Asset), the geometry, the paint vocabulary and the text engine, and nothing above them: a backend knows how to paint, not what a block is. It names no component framework either — the Dioxus shell above it is components, signals and effects over what is here.

Re-exports§

pub use fit::DevicePixelRatio;
pub use fit::fit;
pub use glyphs::Glyphs;
pub use ground::paint_ground;
pub use handoff::clipboard_write;
pub use handoff::download;
pub use images::Images;
pub use input::Reader;
pub use input::Sample;
pub use replay::Repaint;
pub use replay::replay;

Modules§

color 🔒
A resolved swatch as CSS writes it.
cursor 🔒
The pointer shapes the tools ask for, in the browser’s own vocabulary.
fit
The backing store, sized for the display.
glyphs
The diagram’s text engine: one typeface, laid out and inked from its own bytes.
ground
The ground under the diagram: the canvas fill, then the grid over it.
handoff
The two hand-offs a backend can perform without a shell around it: saving bytes to a file and putting text on the clipboard. Both are browser affordances rather than application decisions, which is why they live at this level rather than above it.
images
The backend’s image table.
input
What the browser did, as values with no browser in them.
replay
A display list, drawn.

Functions§

css_color
color as a CSS rgb()/rgba() function. The display list carries premultiplied alpha and CSS does not, so the multiplication is undone here.
css_cursor
The CSS cursor value for cursor, to set on the canvas element.