blockworx/export/
level.rs1use blockworx_editor::{
6 gesture::Gesture,
7 path::BlockPath,
8 presentation::Presentation,
9 widget::{display::render, drawing::Drawing},
10};
11use blockworx_geom::Rect;
12use blockworx_paint::FontChoice;
13
14use crate::{
15 export::svg::SvgRenderer,
16 theme::{Style, Theme},
17};
18
19pub struct RenderedLevel {
25 pub svg: String,
26 pub frame: Rect,
27 pub blocks: Vec<(blockworx_doc::id::BlockId, Rect)>,
28}
29
30pub fn render_svg(
34 theme: &Theme,
35 font: FontChoice,
36 indexed: blockworx_doc::document::IndexedDocument<'_>,
37 path: &BlockPath,
38 presentation: &mut Presentation,
39) -> String {
40 render_level(theme, font, indexed, path, presentation).svg
41}
42
43pub fn render_level(
46 theme: &Theme,
47 font: FontChoice,
48 indexed: blockworx_doc::document::IndexedDocument<'_>,
49 path: &BlockPath,
50 presentation: &mut Presentation,
51) -> RenderedLevel {
52 let mut gesture = Gesture::idle();
54 let mut drawing = Drawing::new(indexed, path, presentation, &mut gesture);
55 let mut svg = SvgRenderer::new(theme.palette().clone(), font);
56 {
57 let mut style = Style::new(theme, &mut svg);
58 drawing.refresh_text_extents(&style);
61 render(&drawing, &mut style);
62 }
63 let blocks = drawing
64 .blocks_layer()
65 .filter_map(|(id, shape)| Some((id.block()?, shape.gui_rect())))
66 .collect();
67 let (svg, frame) = svg.finish();
68 RenderedLevel { svg, frame, blocks }
69}