1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

Painter extend accepts IntoIter (#2249)

* `Painter` extend accepts `IntoIter`

* Update painter.rs
This commit is contained in:
Max Wase
2022-11-07 10:32:28 +02:00
committed by GitHub
parent e48602059d
commit 22a917c00a
4 changed files with 41 additions and 36 deletions

View File

@@ -130,9 +130,12 @@ impl PaintList {
idx
}
pub fn extend(&mut self, clip_rect: Rect, mut shapes: Vec<Shape>) {
self.0
.extend(shapes.drain(..).map(|shape| ClippedShape(clip_rect, shape)));
pub fn extend<I: IntoIterator<Item = Shape>>(&mut self, clip_rect: Rect, shapes: I) {
self.0.extend(
shapes
.into_iter()
.map(|shape| ClippedShape(clip_rect, shape)),
);
}
/// Modify an existing [`Shape`].

View File

@@ -178,19 +178,19 @@ impl Painter {
/// Add many shapes at once.
///
/// Calling this once is generally faster than calling [`Self::add`] multiple times.
pub fn extend(&self, mut shapes: Vec<Shape>) {
pub fn extend<I: IntoIterator<Item = Shape>>(&self, shapes: I) {
if self.fade_to_color == Some(Color32::TRANSPARENT) {
return;
}
if !shapes.is_empty() {
if self.fade_to_color.is_some() {
for shape in &mut shapes {
self.transform_shape(shape);
}
}
if self.fade_to_color.is_some() {
let shapes = shapes.into_iter().map(|mut shape| {
self.transform_shape(&mut shape);
shape
});
self.paint_list().extend(self.clip_rect, shapes);
}
} else {
self.paint_list().extend(self.clip_rect, shapes);
};
}
/// Modify an existing [`Shape`].