Add grid helpers to wasm

This commit is contained in:
alonso.torres 2025-06-10 16:46:19 +02:00
parent 3624a14141
commit 0be8a6e0e6
11 changed files with 259 additions and 68 deletions

View file

@ -0,0 +1,43 @@
use skia_safe::{self as skia, Color4f};
use std::collections::HashMap;
use crate::math::Matrix;
use crate::render::grid_layout;
use crate::shapes::{Shape, StructureEntry};
use crate::uuid::Uuid;
use super::{RenderState, SurfaceId};
pub fn render(
render_state: &mut RenderState,
shapes: &HashMap<Uuid, &mut Shape>,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) {
let canvas = render_state.surfaces.canvas(SurfaceId::UI);
canvas.clear(Color4f::new(0.0, 0.0, 0.0, 0.0));
canvas.save();
let viewbox = render_state.viewbox;
let zoom = viewbox.zoom * render_state.options.dpr();
canvas.scale((zoom, zoom));
canvas.translate((-viewbox.area.left, -viewbox.area.top));
let canvas = render_state.surfaces.canvas(SurfaceId::UI);
if let Some(id) = render_state.show_grid {
if let Some(shape) = shapes.get(&id) {
grid_layout::render_overlay(zoom, canvas, shape, shapes, modifiers, structure);
}
}
canvas.restore();
render_state.surfaces.draw_into(
SurfaceId::UI,
SurfaceId::Target,
Some(&skia::Paint::default()),
);
}