From d2f36a0a58c0ce3acd53a39226dd3b77d892d527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 17 Aug 2025 00:58:37 +0200 Subject: [PATCH] Resize base layer in `Stack` before drawing --- core/src/renderer.rs | 4 ++-- core/src/renderer/null.rs | 2 +- graphics/src/layer.rs | 5 ++++- renderer/src/fallback.rs | 4 ++-- runtime/src/user_interface.rs | 4 +--- tiny_skia/src/lib.rs | 4 ++-- wgpu/src/lib.rs | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 53f59303..84d48304 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -60,8 +60,8 @@ pub trait Renderer { /// Fills a [`Quad`] with the provided [`Background`]. fn fill_quad(&mut self, quad: Quad, background: impl Into); - /// Clears all of the recorded primitives in the [`Renderer`]. - fn clear(&mut self); + /// Resets the [`Renderer`] to start drawing in the `new_bounds` from scratch. + fn reset(&mut self, new_bounds: Rectangle); } /// A polygon with four sides. diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index 2251e527..60c87a81 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -16,7 +16,7 @@ impl Renderer for () { fn end_transformation(&mut self) {} - fn clear(&mut self) {} + fn reset(&mut self, _new_bounds: Rectangle) {} fn fill_quad( &mut self, diff --git a/graphics/src/layer.rs b/graphics/src/layer.rs index 4f4219fd..dbab0192 100644 --- a/graphics/src/layer.rs +++ b/graphics/src/layer.rs @@ -158,12 +158,15 @@ impl Stack { /// Clears the layers of the [`Stack`], allowing reuse. /// + /// It resizes the base layer bounds to the `new_bounds`. + /// /// This will normally keep layer allocations for future drawing operations. - pub fn clear(&mut self) { + pub fn reset(&mut self, new_bounds: Rectangle) { for layer in self.layers[..self.active_count].iter_mut() { layer.reset(); } + self.layers[0].resize(new_bounds); self.current = 0; self.active_count = 1; self.previous.clear(); diff --git a/renderer/src/fallback.rs b/renderer/src/fallback.rs index 79e22c77..411b5862 100644 --- a/renderer/src/fallback.rs +++ b/renderer/src/fallback.rs @@ -46,8 +46,8 @@ where delegate!(self, renderer, renderer.fill_quad(quad, background.into())); } - fn clear(&mut self) { - delegate!(self, renderer, renderer.clear()); + fn reset(&mut self, new_bounds: Rectangle) { + delegate!(self, renderer, renderer.reset(new_bounds)); } fn start_layer(&mut self, bounds: Rectangle) { diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index 95e7574f..482ffafa 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -482,10 +482,8 @@ where style: &renderer::Style, cursor: mouse::Cursor, ) { - // TODO: Move to shell level (?) - renderer.clear(); - let viewport = Rectangle::with_size(self.bounds); + renderer.reset(viewport); let base_cursor = match &self.overlay { None diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs index 8f343277..bc379981 100644 --- a/tiny_skia/src/lib.rs +++ b/tiny_skia/src/lib.rs @@ -225,8 +225,8 @@ impl core::Renderer for Renderer { layer.draw_quad(quad, background.into(), transformation); } - fn clear(&mut self) { - self.layers.clear(); + fn reset(&mut self, new_bounds: Rectangle) { + self.layers.reset(new_bounds); } } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index b5af87b7..4361d605 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -648,8 +648,8 @@ impl core::Renderer for Renderer { layer.draw_quad(quad, background.into(), transformation); } - fn clear(&mut self) { - self.layers.clear(); + fn reset(&mut self, new_bounds: Rectangle) { + self.layers.reset(new_bounds); } }