Introduce layer clipping

This commit is contained in:
Antonio Scandurra
2021-03-26 10:28:05 +01:00
parent 63f9719c99
commit 61d4da9934
5 changed files with 47 additions and 17 deletions
+6 -5
View File
@@ -1,6 +1,7 @@
use crate::{
geometry::vector::Vector2F, AfterLayoutContext, Element, ElementBox, Event, EventContext,
LayoutContext, PaintContext, SizeConstraint,
geometry::{rect::RectF, vector::Vector2F},
AfterLayoutContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
SizeConstraint,
};
pub struct Stack {
@@ -44,12 +45,12 @@ impl Element for Stack {
fn paint(
&mut self,
bounds: pathfinder_geometry::rect::RectF,
bounds: RectF,
_: &mut Self::LayoutState,
ctx: &mut PaintContext,
) -> Self::PaintState {
for child in &mut self.children {
ctx.scene.push_layer();
ctx.scene.push_layer(None);
child.paint(bounds.origin(), ctx);
ctx.scene.pop_layer();
}
@@ -58,7 +59,7 @@ impl Element for Stack {
fn dispatch_event(
&mut self,
event: &Event,
_: pathfinder_geometry::rect::RectF,
_: RectF,
_: &mut Self::LayoutState,
_: &mut Self::PaintState,
ctx: &mut EventContext,
+3 -5
View File
@@ -195,10 +195,7 @@ where
layout: &mut Self::LayoutState,
ctx: &mut PaintContext,
) -> Self::PaintState {
// ctx.canvas.save();
// let mut clip_path = Path2D::new();
// clip_path.rect(RectF::new(origin, self.size.unwrap()));
// ctx.canvas.clip_path(clip_path, FillRule::Winding);
ctx.scene.push_layer(Some(bounds));
let mut item_origin =
bounds.origin() - vec2f(0.0, self.state.scroll_top() % layout.item_height);
@@ -207,7 +204,8 @@ where
item.paint(item_origin, ctx);
item_origin += vec2f(0.0, layout.item_height);
}
// ctx.canvas.restore();
ctx.scene.pop_layer();
}
fn dispatch_event(