mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
craft-ui: a record's clip with no area is Rect::NOTHING
A cut member's shapes record an empty clip that came about in different ways in different passes; one clip passes nothing.
This commit is contained in:
@@ -413,8 +413,8 @@ pub(crate) fn record_shapes_in(ctx: &Context, viewport: ViewportId, layer: Layer
|
||||
let shapes: Vec<Shape<Id>> = 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);
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user