[Rust] Drawable and NestedLayerSlice understand a content frame
@@ -19,16 +19,23 @@ pub trait NestedLayerSlice: Drawable {
let parent = self.get_parent().unwrap().upgrade().unwrap();
let parent_slice = parent.get_slice();
+ let mut content_frame = parent.content_frame();
+ content_frame.origin = content_frame.origin - parent_slice.frame.origin;
+
+ let constrained_to_content_frame = content_frame.constrain(self.frame());
parent_slice.get_slice(Rect::from_parts(
- parent.frame().origin + self.frame().origin,
- self.frame().size,
+ parent.frame().origin + content_frame.origin + self.frame().origin,
+ constrained_to_content_frame.size,
))
}
}
pub trait Drawable {
fn frame(&self) -> Rect;
- fn draw(&self, onto: &mut LayerSlice);
+
+ fn content_frame(&self) -> Rect;
+
+ fn draw(&self);
}
#[derive(Debug, Copy, Clone)]
