diff --git a/crates/egui/src/layers.rs b/crates/egui/src/layers.rs index 914f8240..f448436a 100644 --- a/crates/egui/src/layers.rs +++ b/crates/egui/src/layers.rs @@ -267,15 +267,26 @@ impl PaintList { self.0.is_empty() } - /// Returns the index of the new [`Shape`] that can be used with `PaintList::set`. + /// Returns the index of the new [`Shape`] at index `z` that can be used with `PaintList::set`. #[inline(always)] - pub fn add(&mut self, clip_rect: Rect, shape: Shape, z: ZOrder) -> ShapeIdx { + pub fn add_at_z(&mut self, clip_rect: Rect, shape: Shape, z: ZOrder) -> ShapeIdx { let idx = ShapeIdx(self.0.len()); self.0.push((z, ClippedShape(clip_rect, shape))); idx } - pub fn extend>(&mut self, clip_rect: Rect, shapes: I, z: ZOrder) { + /// Returns the index of the new [`Shape`] at base z-index that can be used with `PaintList::set`. + #[inline(always)] + pub fn add(&mut self, clip_rect: Rect, shape: Shape) -> ShapeIdx { + self.add_at_z(clip_rect, shape, ZOrder::base()) + } + + pub fn extend_at_z>( + &mut self, + clip_rect: Rect, + shapes: I, + z: ZOrder, + ) { self.0.extend( shapes .into_iter() @@ -283,6 +294,10 @@ impl PaintList { ); } + pub fn extend>(&mut self, clip_rect: Rect, shapes: I) { + self.extend_at_z(clip_rect, shapes, ZOrder::base()); + } + /// Modify an existing [`Shape`]. /// /// Sometimes you want to paint a frame behind some contents, but don't know how large the frame needs to be diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index eaae7156..37f3c452 100644 --- a/crates/egui/src/painter.rs +++ b/crates/egui/src/painter.rs @@ -197,12 +197,13 @@ impl Painter { } fn add_to_paint_list(&self, shape: Shape) -> ShapeIdx { - self.paint_list().add(self.clip_rect, shape, self.layer.z) + self.paint_list() + .add_at_z(self.clip_rect, shape, self.layer.z) } fn extend_paint_list(&self, shapes: impl IntoIterator) { self.paint_list() - .extend(self.clip_rect, shapes, self.layer.z); + .extend_at_z(self.clip_rect, shapes, self.layer.z); } fn set_shape_in_paint_list(&self, idx: ShapeIdx, shape: Shape) {