summaryrefslogtreecommitdiff
path: root/src/eval/layout.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-07 10:50:39 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-07 11:07:00 +0200
commit3d52387eea321e94c13b61666f7a758052b20c5d (patch)
tree5c55c51ca7e4b53dee61d280c39b7f664b8b9d6b /src/eval/layout.rs
parent20b4d590b3efbd9b7a44fd6d3a658e7b84d21b99 (diff)
Rework style chains
Diffstat (limited to 'src/eval/layout.rs')
-rw-r--r--src/eval/layout.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/eval/layout.rs b/src/eval/layout.rs
index 94375c61..aecc7ef9 100644
--- a/src/eval/layout.rs
+++ b/src/eval/layout.rs
@@ -1,12 +1,12 @@
//! Layouting infrastructure.
-use std::any::{Any, TypeId};
+use std::any::Any;
use std::fmt::{self, Debug, Formatter};
use std::hash::Hash;
use std::sync::Arc;
+use super::{Barrier, StyleChain};
use crate::diag::TypResult;
-use crate::eval::StyleChain;
use crate::frame::{Element, Frame, Geometry, Shape, Stroke};
use crate::geom::{Align, Length, Linear, Paint, Point, Sides, Size, Spec, Transform};
use crate::library::graphics::MoveNode;
@@ -18,7 +18,7 @@ use crate::Context;
///
/// Layout return one frame per used region alongside constraints that define
/// whether the result is reusable in other regions.
-pub trait Layout {
+pub trait Layout: 'static {
/// Layout this node into the given regions, producing constrained frames.
fn layout(
&self,
@@ -144,12 +144,12 @@ impl LayoutNode {
/// Check whether the contained node is a specific layout node.
pub fn is<T: 'static>(&self) -> bool {
- self.0.as_any().is::<T>()
+ (**self.0).as_any().is::<T>()
}
- /// The type id of this node.
- pub fn id(&self) -> TypeId {
- self.0.as_any().type_id()
+ /// A barrier for the node.
+ pub fn barrier(&self) -> Barrier {
+ (**self.0).barrier()
}
/// Try to downcast to a specific layout node.
@@ -157,7 +157,7 @@ impl LayoutNode {
where
T: Layout + Debug + Hash + 'static,
{
- self.0.as_any().downcast_ref()
+ (**self.0).as_any().downcast_ref()
}
/// Force a size for this node.
@@ -223,7 +223,7 @@ impl Layout for LayoutNode {
styles: StyleChain,
) -> TypResult<Vec<Arc<Frame>>> {
ctx.query((self, regions, styles), |ctx, (node, regions, styles)| {
- node.0.layout(ctx, regions, styles.barred(node.id()))
+ node.0.layout(ctx, regions, node.barrier().chain(&styles))
})
.clone()
}
@@ -253,6 +253,7 @@ impl PartialEq for LayoutNode {
trait Bounds: Layout + Debug + Sync + Send + 'static {
fn as_any(&self) -> &dyn Any;
+ fn barrier(&self) -> Barrier;
}
impl<T> Bounds for T
@@ -262,6 +263,10 @@ where
fn as_any(&self) -> &dyn Any {
self
}
+
+ fn barrier(&self) -> Barrier {
+ Barrier::new::<T>()
+ }
}
/// A layout node that produces an empty frame.