Skip to content

Commit 0dec3a3

Browse files
committed
Add algorithm-specific PartialLayoutTree traits
1 parent 551881c commit 0dec3a3

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/tree/mod.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Contains both [a high-level interface to Taffy](crate::Taffy) using a ready-made node tree, and [a trait for defining a custom node trees](crate::tree::LayoutTree) / utility types to help with that.
22
33
use crate::geometry::{Line, Size};
4-
use crate::style::{AvailableSpace, Style};
4+
use crate::style::{
5+
AvailableSpace, CoreStyle, FlexboxContainerStyle, FlexboxItemStyle, GridContainerStyle, GridItemStyle, Style,
6+
};
57

68
// Submodules
79
mod cache;
@@ -59,6 +61,63 @@ pub trait LayoutTree: PartialLayoutTree {
5961
fn get_final_layout_mut(&mut self, node_id: NodeId) -> &mut Layout;
6062
}
6163

64+
#[cfg(feature = "flexbox")]
65+
/// Extends [`PartialLayoutTree`] with getters for the styles required for Flexbox layout
66+
pub trait FlexboxPartialLayoutTree: PartialLayoutTree {
67+
/// The style type representing the Flexbox container's styles
68+
type ContainerStyle<'a>: FlexboxContainerStyle
69+
where
70+
Self: 'a;
71+
/// The style type representing each Flexbox item's styles
72+
type ItemStyle<'a>: FlexboxItemStyle
73+
where
74+
Self: 'a;
75+
76+
/// Get the container's styles
77+
fn get_container_style<'a>(&'a self, node_id: NodeId) -> Self::ContainerStyle<'a>;
78+
79+
/// Get the child's styles
80+
fn get_child_style<'a>(&'a self, child_node_id: NodeId) -> Self::ItemStyle<'a>;
81+
}
82+
83+
#[cfg(feature = "grid")]
84+
/// Extends [`PartialLayoutTree`] with getters for the styles required for CSS Grid layout
85+
pub trait GridPartialLayoutTree: PartialLayoutTree {
86+
/// The style type representing the CSS Grid container's styles
87+
type ContainerStyle<'a>: GridContainerStyle
88+
where
89+
Self: 'a;
90+
/// The style type representing each CSS Grid item's styles
91+
type ItemStyle<'a>: GridItemStyle
92+
where
93+
Self: 'a;
94+
95+
/// Get the container's styles
96+
fn get_container_style<'a>(&'a self, node_id: NodeId) -> Self::ContainerStyle<'a>;
97+
98+
/// Get the child's styles
99+
fn get_child_style<'a>(&'a self, child_node_id: NodeId) -> Self::ItemStyle<'a>;
100+
}
101+
102+
#[cfg(feature = "block_layout")]
103+
/// Extends [`PartialLayoutTree`] with getters for the styles required for CSS Block layout
104+
pub trait BlockPartialLayoutTree: PartialLayoutTree {
105+
/// The style type representing the CSS Block container's styles
106+
type ContainerStyle<'a>: CoreStyle
107+
where
108+
Self: 'a;
109+
/// The style type representing each CSS Block item's styles
110+
type ItemStyle<'a>: CoreStyle
111+
where
112+
Self: 'a;
113+
114+
/// Get the container's styles
115+
fn get_container_style<'a>(&'a self, node_id: NodeId) -> Self::ContainerStyle<'a>;
116+
117+
/// Get the child's styles
118+
fn get_child_style<'a>(&'a self, child_node_id: NodeId) -> Self::ItemStyle<'a>;
119+
}
120+
62121
/// A private trait which allows us to add extra convenience methods to types which implement
63122
/// LayoutTree without making those methods public.
64123
pub(crate) trait PartialLayoutTreeExt: PartialLayoutTree {

0 commit comments

Comments
 (0)