mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 22:46:10 +02:00
🎉 Save shape data in rust memory
This commit is contained in:
parent
48909dc3c4
commit
65ee2f9081
13 changed files with 479 additions and 297 deletions
36
render-wasm/src/state.rs
Normal file
36
render-wasm/src/state.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use skia_safe as skia;
|
||||
use std::collections::HashMap;
|
||||
use std::vec::Vec;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::render::RenderState;
|
||||
use crate::shapes::Shape;
|
||||
|
||||
/// This struct holds the state of the Rust application between JS calls.
|
||||
///
|
||||
/// It is created by [init] and passed to the other exported functions.
|
||||
/// Note that rust-skia data structures are not thread safe, so a state
|
||||
/// must not be shared between different Web Workers.
|
||||
pub(crate) struct State<'a> {
|
||||
pub render_state: RenderState,
|
||||
pub current_id: Option<Uuid>,
|
||||
pub current_shape: Option<&'a mut Shape>,
|
||||
pub shapes: HashMap<Uuid, Shape>,
|
||||
pub display_list: Vec<Uuid>,
|
||||
}
|
||||
|
||||
impl<'a> State<'a> {
|
||||
pub fn with_capacity(width: i32, height: i32, capacity: usize) -> Self {
|
||||
State {
|
||||
render_state: RenderState::new(width, height),
|
||||
current_id: None,
|
||||
current_shape: None,
|
||||
shapes: HashMap::with_capacity(capacity),
|
||||
display_list: Vec::with_capacity(capacity),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_surface(&mut self, surface: skia::Surface) {
|
||||
self.render_state.surface = surface;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue