Add `ui.shrink_clip_rect` (#5068)
This commit is contained in:
parent
454abf705b
commit
0b92b93233
|
|
@ -151,8 +151,21 @@ impl Painter {
|
||||||
self.clip_rect
|
self.clip_rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Constrain the rectangle in which we can paint.
|
||||||
|
///
|
||||||
|
/// Short for `painter.set_clip_rect(painter.clip_rect().intersect(new_clip_rect))`.
|
||||||
|
///
|
||||||
|
/// See also: [`Self::clip_rect`] and [`Self::set_clip_rect`].
|
||||||
|
#[inline]
|
||||||
|
pub fn shrink_clip_rect(&mut self, new_clip_rect: Rect) {
|
||||||
|
self.clip_rect = self.clip_rect.intersect(new_clip_rect);
|
||||||
|
}
|
||||||
|
|
||||||
/// Everything painted in this [`Painter`] will be clipped against this.
|
/// Everything painted in this [`Painter`] will be clipped against this.
|
||||||
/// This means nothing outside of this rectangle will be visible on screen.
|
/// This means nothing outside of this rectangle will be visible on screen.
|
||||||
|
///
|
||||||
|
/// Warning: growing the clip rect might cause unexpected results!
|
||||||
|
/// When in doubt, use [`Self::shrink_clip_rect`] instead.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_clip_rect(&mut self, clip_rect: Rect) {
|
pub fn set_clip_rect(&mut self, clip_rect: Rect) {
|
||||||
self.clip_rect = clip_rect;
|
self.clip_rect = clip_rect;
|
||||||
|
|
|
||||||
|
|
@ -643,8 +643,21 @@ impl Ui {
|
||||||
self.painter.clip_rect()
|
self.painter.clip_rect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Constrain the rectangle in which we can paint.
|
||||||
|
///
|
||||||
|
/// Short for `ui.set_clip_rect(ui.clip_rect().intersect(new_clip_rect))`.
|
||||||
|
///
|
||||||
|
/// See also: [`Self::clip_rect`] and [`Self::set_clip_rect`].
|
||||||
|
#[inline]
|
||||||
|
pub fn shrink_clip_rect(&mut self, new_clip_rect: Rect) {
|
||||||
|
self.painter.shrink_clip_rect(new_clip_rect);
|
||||||
|
}
|
||||||
|
|
||||||
/// Screen-space rectangle for clipping what we paint in this ui.
|
/// Screen-space rectangle for clipping what we paint in this ui.
|
||||||
/// This is used, for instance, to avoid painting outside a window that is smaller than its contents.
|
/// This is used, for instance, to avoid painting outside a window that is smaller than its contents.
|
||||||
|
///
|
||||||
|
/// Warning: growing the clip rect might cause unexpected results!
|
||||||
|
/// When in doubt, use [`Self::shrink_clip_rect`] instead.
|
||||||
pub fn set_clip_rect(&mut self, clip_rect: Rect) {
|
pub fn set_clip_rect(&mut self, clip_rect: Rect) {
|
||||||
self.painter.set_clip_rect(clip_rect);
|
self.painter.set_clip_rect(clip_rect);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ impl<'l> StripLayout<'l> {
|
||||||
let margin = egui::Vec2::splat(self.ui.visuals().clip_rect_margin);
|
let margin = egui::Vec2::splat(self.ui.visuals().clip_rect_margin);
|
||||||
let margin = margin.min(0.5 * self.ui.spacing().item_spacing);
|
let margin = margin.min(0.5 * self.ui.spacing().item_spacing);
|
||||||
let clip_rect = max_rect.expand2(margin);
|
let clip_rect = max_rect.expand2(margin);
|
||||||
child_ui.set_clip_rect(clip_rect.intersect(child_ui.clip_rect()));
|
child_ui.shrink_clip_rect(clip_rect);
|
||||||
|
|
||||||
if !child_ui.is_sizing_pass() {
|
if !child_ui.is_sizing_pass() {
|
||||||
// Better to truncate (if we can), rather than hard clipping:
|
// Better to truncate (if we can), rather than hard clipping:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue