0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

🐛 Fix surface not being resized when viewport dimensions changed

This commit is contained in:
Belén Albeza 2024-11-18 16:58:58 +01:00
parent 2f15844c32
commit dfe8f97f8d
2 changed files with 22 additions and 20 deletions

View file

@ -1,9 +1,9 @@
pub mod images;
pub mod render;
pub mod shapes;
pub mod state;
pub mod utils;
pub mod view;
pub mod images;
use skia_safe as skia;
@ -36,14 +36,6 @@ pub extern "C" fn init(width: i32, height: i32) {
}
}
/// This is called from JS when the window is resized.
/// # Safety
#[no_mangle]
pub unsafe extern "C" fn resize_surface(width: i32, height: i32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
state.render_state.resize(width, height);
}
#[no_mangle]
pub unsafe extern "C" fn render() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
@ -51,7 +43,7 @@ pub unsafe extern "C" fn render() {
}
#[no_mangle]
pub unsafe extern "C" fn navigate() {
pub unsafe extern "C" fn navigate() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
state.navigate();
}
@ -65,11 +57,7 @@ pub extern "C" fn reset_canvas() {
#[no_mangle]
pub extern "C" fn set_view(zoom: f32, x: f32, y: f32, width: f32, height: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
state.view.zoom = zoom;
state.view.x = x;
state.view.y = y;
state.view.width = width;
state.view.height = height;
state.set_view(zoom, (x, y), (width, height));
}
#[no_mangle]

View file

@ -31,7 +31,7 @@ impl<'a> State<'a> {
zoom: 1.,
width: 0.,
height: 0.,
}
},
}
}
@ -40,13 +40,11 @@ impl<'a> State<'a> {
}
pub fn navigate(&mut self) {
self.render_state
.navigate(&self.view, &self.shapes);
self.render_state.navigate(&self.view, &self.shapes);
}
pub fn draw_all_shapes(&mut self) {
self.render_state
.draw_all_shapes(&self.view, &self.shapes);
self.render_state.draw_all_shapes(&self.view, &self.shapes);
}
pub fn use_shape(&'a mut self, id: Uuid) {
@ -62,4 +60,20 @@ 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);
}
}
}