mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 09:46:12 +02:00
🎉 Render only visible shapes
This commit is contained in:
parent
f9912e0299
commit
f7ff3129ed
11 changed files with 235 additions and 103 deletions
|
@ -3,7 +3,8 @@ use uuid::Uuid;
|
|||
|
||||
use crate::render::RenderState;
|
||||
use crate::shapes::Shape;
|
||||
use crate::view::View;
|
||||
use crate::view::Viewbox;
|
||||
use crate::math;
|
||||
|
||||
/// This struct holds the state of the Rust application between JS calls.
|
||||
///
|
||||
|
@ -11,40 +12,50 @@ use crate::view::View;
|
|||
/// 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 debug: u32,
|
||||
pub render_state: RenderState,
|
||||
pub current_id: Option<Uuid>,
|
||||
pub current_shape: Option<&'a mut Shape>,
|
||||
pub shapes: HashMap<Uuid, Shape>,
|
||||
pub view: View,
|
||||
pub viewbox: Viewbox,
|
||||
}
|
||||
|
||||
impl<'a> State<'a> {
|
||||
pub fn with_capacity(width: i32, height: i32, capacity: usize) -> Self {
|
||||
pub fn with_capacity(width: i32, height: i32, debug: u32, capacity: usize) -> Self {
|
||||
State {
|
||||
debug,
|
||||
render_state: RenderState::new(width, height),
|
||||
current_id: None,
|
||||
current_shape: None,
|
||||
shapes: HashMap::with_capacity(capacity),
|
||||
view: View {
|
||||
viewbox: Viewbox {
|
||||
x: 0.,
|
||||
y: 0.,
|
||||
zoom: 1.,
|
||||
width: 0.,
|
||||
height: 0.,
|
||||
},
|
||||
width: width as f32,
|
||||
height: height as f32,
|
||||
area: math::Rect::new_empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, width: i32, height: i32) {
|
||||
self.render_state.resize(width, height);
|
||||
self.viewbox.set_wh(width as f32, height as f32);
|
||||
}
|
||||
|
||||
pub fn render_state(&'a mut self) -> &'a mut RenderState {
|
||||
&mut self.render_state
|
||||
}
|
||||
|
||||
pub fn navigate(&mut self) {
|
||||
self.render_state.navigate(&self.view, &self.shapes);
|
||||
self.render_state
|
||||
.navigate(&self.viewbox, &self.shapes, self.debug);
|
||||
}
|
||||
|
||||
pub fn draw_all_shapes(&mut self) {
|
||||
self.render_state.draw_all_shapes(&self.view, &self.shapes);
|
||||
pub fn render_all(&mut self) {
|
||||
self.render_state
|
||||
.render_all(&self.viewbox, &self.shapes, self.debug);
|
||||
}
|
||||
|
||||
pub fn use_shape(&'a mut self, id: Uuid) {
|
||||
|
@ -60,20 +71,4 @@ impl<'a> State<'a> {
|
|||
pub fn current_shape(&'a mut self) -> Option<&'a mut Shape> {
|
||||
self.current_shape.as_deref_mut()
|
||||
}
|
||||
|
||||
pub fn set_view(&mut self, zoom: f32, pan: (f32, f32), size: (f32, f32)) {
|
||||
let (x, y) = pan;
|
||||
self.view.x = x;
|
||||
self.view.y = y;
|
||||
|
||||
self.view.zoom = zoom;
|
||||
|
||||
let (w, h) = size;
|
||||
if self.view.width != w || self.view.height != h {
|
||||
self.view.width = w;
|
||||
self.view.height = h;
|
||||
|
||||
self.render_state.resize(w as i32, h as i32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue