blockworx_editor/render/image.rs
1use blockworx_doc::block_model::Asset;
2use blockworx_geom::Rect;
3use blockworx_paint::Renderer;
4
5use crate::theme::Style;
6
7/// Draw `asset` stretched to fill `bbox`. The image's intrinsic aspect ratio
8/// is not preserved — the box is resized freely by its corners. The painter
9/// resolves and caches the image; an asset the document does not hold
10/// (`None`, which the zero icon's null hash also reads as) or one that fails
11/// to parse draws nothing.
12pub fn draw_block_image(bbox: Rect, asset: Option<&Asset>, painter: &mut Style<'_, impl Renderer>) {
13 let Some(asset) = asset else { return };
14 if painter.image_intrinsic_size(asset).is_none() {
15 return;
16 }
17 painter.draw_image(bbox, asset);
18}