blitz_paint/lib.rs
1//! Paint a [`blitz_dom::BaseDocument`] by pushing [`anyrender`] drawing commands into
2//! an impl [`anyrender::PaintScene`].
3
4#![allow(clippy::collapsible_if)]
5
6mod color;
7mod debug_overlay;
8mod gradient;
9mod kurbo_css;
10mod layers;
11mod render;
12mod sizing;
13mod text;
14
15use anyrender::PaintScene;
16use blitz_dom::{BaseDocument, util::Color};
17use render::BlitzDomPainter;
18
19/// Paint a [`blitz_dom::BaseDocument`] by pushing drawing commands into
20/// an impl [`anyrender::PaintScene`].
21///
22/// This function assumes that the styles and layout in the [`BaseDocument`] are already
23/// resolved. Please ensure that this is the case before trying to paint.
24///
25/// The implementation of [`PaintScene`] is responsible for handling the commands that are pushed into it.
26/// Generally this will involve executing them to draw a rasterized image/texture. But in some cases it may choose to
27/// transform them to a vector format (e.g. SVG/PDF) or serialize them in raw form for later use.
28pub fn paint_scene(
29 scene: &mut impl PaintScene,
30 dom: &BaseDocument,
31 scale: f64,
32 width: u32,
33 height: u32,
34 x_offset: u32,
35 y_offset: u32,
36) {
37 let generator =
38 BlitzDomPainter::new(dom, scale, width, height, x_offset as f64, y_offset as f64);
39 generator.paint_scene(scene);
40
41 // println!(
42 // "Rendered using {} clips (depth: {}) (wanted: {})",
43 // CLIPS_USED.load(atomic::Ordering::SeqCst),
44 // CLIP_DEPTH_USED.load(atomic::Ordering::SeqCst),
45 // CLIPS_WANTED.load(atomic::Ordering::SeqCst)
46 // );
47}
48
49const SELECTION_COLOR: Color = Color::from_rgb8(180, 213, 255);