Resize base layer in Stack before drawing

This commit is contained in:
Héctor Ramón Jiménez 2025-08-17 00:58:37 +02:00
parent 46167c78c7
commit d2f36a0a58
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
7 changed files with 14 additions and 13 deletions

View file

@ -60,8 +60,8 @@ pub trait Renderer {
/// Fills a [`Quad`] with the provided [`Background`]. /// Fills a [`Quad`] with the provided [`Background`].
fn fill_quad(&mut self, quad: Quad, background: impl Into<Background>); fn fill_quad(&mut self, quad: Quad, background: impl Into<Background>);
/// Clears all of the recorded primitives in the [`Renderer`]. /// Resets the [`Renderer`] to start drawing in the `new_bounds` from scratch.
fn clear(&mut self); fn reset(&mut self, new_bounds: Rectangle);
} }
/// A polygon with four sides. /// A polygon with four sides.

View file

@ -16,7 +16,7 @@ impl Renderer for () {
fn end_transformation(&mut self) {} fn end_transformation(&mut self) {}
fn clear(&mut self) {} fn reset(&mut self, _new_bounds: Rectangle) {}
fn fill_quad( fn fill_quad(
&mut self, &mut self,

View file

@ -158,12 +158,15 @@ impl<T: Layer> Stack<T> {
/// Clears the layers of the [`Stack`], allowing reuse. /// 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. /// 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() { for layer in self.layers[..self.active_count].iter_mut() {
layer.reset(); layer.reset();
} }
self.layers[0].resize(new_bounds);
self.current = 0; self.current = 0;
self.active_count = 1; self.active_count = 1;
self.previous.clear(); self.previous.clear();

View file

@ -46,8 +46,8 @@ where
delegate!(self, renderer, renderer.fill_quad(quad, background.into())); delegate!(self, renderer, renderer.fill_quad(quad, background.into()));
} }
fn clear(&mut self) { fn reset(&mut self, new_bounds: Rectangle) {
delegate!(self, renderer, renderer.clear()); delegate!(self, renderer, renderer.reset(new_bounds));
} }
fn start_layer(&mut self, bounds: Rectangle) { fn start_layer(&mut self, bounds: Rectangle) {

View file

@ -482,10 +482,8 @@ where
style: &renderer::Style, style: &renderer::Style,
cursor: mouse::Cursor, cursor: mouse::Cursor,
) { ) {
// TODO: Move to shell level (?)
renderer.clear();
let viewport = Rectangle::with_size(self.bounds); let viewport = Rectangle::with_size(self.bounds);
renderer.reset(viewport);
let base_cursor = match &self.overlay { let base_cursor = match &self.overlay {
None None

View file

@ -225,8 +225,8 @@ impl core::Renderer for Renderer {
layer.draw_quad(quad, background.into(), transformation); layer.draw_quad(quad, background.into(), transformation);
} }
fn clear(&mut self) { fn reset(&mut self, new_bounds: Rectangle) {
self.layers.clear(); self.layers.reset(new_bounds);
} }
} }

View file

@ -648,8 +648,8 @@ impl core::Renderer for Renderer {
layer.draw_quad(quad, background.into(), transformation); layer.draw_quad(quad, background.into(), transformation);
} }
fn clear(&mut self) { fn reset(&mut self, new_bounds: Rectangle) {
self.layers.clear(); self.layers.reset(new_bounds);
} }
} }