Rename Painter::sub_region
to Painter::with_clip_rect
This commit is contained in:
parent
2d2022fb72
commit
5414e8a7fb
5 changed files with 22 additions and 11 deletions
|
@ -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)).
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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`].
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue