diff --git a/CHANGELOG.md b/CHANGELOG.md index afb56641..53b477ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w * MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)). * Renamed the feature `convert_bytemuck` to `bytemuck` ([#1467](https://github.com/emilk/egui/pull/1467)). * Renamed the feature `serialize` to `serde` ([#1467](https://github.com/emilk/egui/pull/1467)). +* Renamed `Painter::sub_region` to `Painter::with_clip_rect`. ### Fixed 🐛 * Fixed `ComboBox`:es always being rendered left-aligned ([#1304](https://github.com/emilk/egui/pull/1304)). diff --git a/egui/src/painter.rs b/egui/src/painter.rs index 6534c30d..89d29f80 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -54,6 +54,19 @@ impl Painter { } } + /// Create a painter for a sub-region of this [`Painter`]. + /// + /// The clip-rect of the returned [`Painter`] will be the intersection + /// of the given rectangle and the `clip_rect()` of the parent [`Painter`]. + pub fn with_clip_rect(&self, rect: Rect) -> Self { + Self { + ctx: self.ctx.clone(), + layer_id: self.layer_id, + clip_rect: rect.intersect(self.clip_rect), + fade_to_color: self.fade_to_color, + } + } + /// Redirect where you are painting. pub fn set_layer_id(&mut self, layer_id: LayerId) { self.layer_id = layer_id; @@ -73,10 +86,7 @@ impl Painter { self.fade_to_color = Some(Color32::TRANSPARENT); } - /// Create a painter for a sub-region of this [`Painter`]. - /// - /// The clip-rect of the returned [`Painter`] will be the intersection - /// of the given rectangle and the `clip_rect()` of this [`Painter`]. + #[deprecated = "Use Painter::with_clip_rect"] // Deprecated in 2022-04-18, before egui 0.18 pub fn sub_region(&self, rect: Rect) -> Self { Self { ctx: self.ctx.clone(), @@ -197,7 +207,7 @@ impl Painter { /// ## Debug painting impl Painter { #[allow(clippy::needless_pass_by_value)] - pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl ToString) { + pub fn debug_rect(&self, rect: Rect, color: Color32, text: impl ToString) { self.rect_stroke(rect, 0.0, (1.0, color)); self.text( rect.min, diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 804c61a3..65c52bd2 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -305,7 +305,7 @@ impl Ui { /// The clip-rect of the returned [`Painter`] will be the intersection /// of the given rectangle and the `clip_rect()` of this [`Ui`]. pub fn painter_at(&self, rect: Rect) -> Painter { - self.painter().sub_region(rect) + self.painter().with_clip_rect(rect) } /// Use this to paint stuff within this [`Ui`]. diff --git a/egui/src/widgets/plot/mod.rs b/egui/src/widgets/plot/mod.rs index 15a8ce35..7efb4b81 100644 --- a/egui/src/widgets/plot/mod.rs +++ b/egui/src/widgets/plot/mod.rs @@ -547,7 +547,7 @@ impl Plot { // Background if show_background { - ui.painter().sub_region(rect).add(epaint::RectShape { + ui.painter().with_clip_rect(rect).add(epaint::RectShape { rect, rounding: Rounding::same(2.0), fill: ui.visuals().extreme_bg_color, @@ -710,8 +710,8 @@ impl Plot { prepared.ui(ui, &response); if let Some(boxed_zoom_rect) = boxed_zoom_rect { - ui.painter().sub_region(rect).add(boxed_zoom_rect.0); - ui.painter().sub_region(rect).add(boxed_zoom_rect.1); + ui.painter().with_clip_rect(rect).add(boxed_zoom_rect.0); + ui.painter().with_clip_rect(rect).add(boxed_zoom_rect.1); } if let Some(mut legend) = legend { @@ -955,7 +955,7 @@ impl PreparedPlot { self.hover(ui, pointer, &mut shapes); } - let painter = ui.painter().sub_region(*transform.frame()); + let painter = ui.painter().with_clip_rect(*transform.frame()); painter.extend(shapes); if let Some((corner, formatter)) = self.coordinates_formatter.as_ref() { diff --git a/egui/src/widgets/progress_bar.rs b/egui/src/widgets/progress_bar.rs index c89f1002..3c9aaa06 100644 --- a/egui/src/widgets/progress_bar.rs +++ b/egui/src/widgets/progress_bar.rs @@ -140,7 +140,7 @@ impl Widget for ProgressBar { .override_text_color .unwrap_or(visuals.selection.stroke.color); galley.paint_with_fallback_color( - &ui.painter().sub_region(outer_rect), + &ui.painter().with_clip_rect(outer_rect), text_pos, text_color, );