diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 5884981da..4d309774f 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -413,8 +413,8 @@ pub(crate) fn record_shapes_in(ctx: &Context, viewport: ViewportId, layer: Layer let shapes: Vec> = shapes.into_iter().collect(); crate::runtime::replay::journal( ctx, - || (layer, root, crate::runtime::Clip(clip), shapes.clone()), - |ctx, (layer, root, clip, shapes)| record_shapes(ctx, *layer, *root, clip.0, shapes.iter().cloned()), + || (layer, root, crate::runtime::Clip::new(clip), shapes.clone()), + |ctx, (layer, root, clip, shapes)| record_shapes(ctx, *layer, *root, clip.rect(), shapes.iter().cloned()), ); add_shapes_in(ctx, viewport, layer, root, clip, shapes); } diff --git a/crates/ui-contract/src/runtime/shift.rs b/crates/ui-contract/src/runtime/shift.rs index 3b7017f74..351f25377 100644 --- a/crates/ui-contract/src/runtime/shift.rs +++ b/crates/ui-contract/src/runtime/shift.rs @@ -16,13 +16,26 @@ pub trait Shift { } /// A clip rect a record holds: the clip of the code around the record becomes the replay's clip, a clip set inside it -/// moves with it (`RecordShift::clip`). +/// moves with it (`RecordShift::clip`). A clip with no area is `Rect::NOTHING`, however it came about: one clip passes +/// nothing. #[derive(Clone, Copy, Debug, PartialEq)] -pub struct Clip(pub Rect); +pub struct Clip(Rect); + +impl Clip { + /// The record's clip for the clip rect `clip`. + pub fn new(clip: Rect) -> Self { + Clip(if clip.is_positive() { clip } else { Rect::NOTHING }) + } + + /// The clip rect. + pub fn rect(self) -> Rect { + self.0 + } +} impl Shift for Clip { fn shifted(&self, by: &RecordShift) -> Self { - Clip(by.clip(self.0)) + Clip::new(by.clip(self.0)) } }