Resize surface in configure_surface in iced_tiny_skia

This commit is contained in:
Héctor Ramón Jiménez 2024-01-18 10:52:25 +01:00
parent 150ce65e20
commit 3cf8f77d65
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -57,14 +57,18 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
)
.expect("Create softbuffer surface for window");
Surface {
let mut surface = Surface {
window,
clip_mask: tiny_skia::Mask::new(width, height)
.expect("Create clip mask"),
primitive_stack: VecDeque::new(),
background_color: Color::BLACK,
max_age: 0,
}
};
self.configure_surface(&mut surface, width, height);
surface
}
fn configure_surface(
@ -73,6 +77,14 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
width: u32,
height: u32,
) {
surface
.window
.resize(
NonZeroU32::new(width).expect("Non-zero width"),
NonZeroU32::new(height).expect("Non-zero height"),
)
.expect("Resize surface");
surface.clip_mask =
tiny_skia::Mask::new(width, height).expect("Create clip mask");
surface.primitive_stack.clear();
@ -152,14 +164,6 @@ pub fn present<T: AsRef<str>>(
let physical_size = viewport.physical_size();
let scale_factor = viewport.scale_factor() as f32;
surface
.window
.resize(
NonZeroU32::new(physical_size.width).unwrap(),
NonZeroU32::new(physical_size.height).unwrap(),
)
.unwrap();
let mut buffer = surface
.window
.buffer_mut()