Skip to content

Commit 412c075

Browse files
committed
Add algorithm-specific PartialLayoutTree traits
1 parent cb0f2f7 commit 412c075

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

src/tree/mod.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
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::{AvailableSpace, CoreStyle, Style};
5+
#[cfg(feature = "flexbox")]
6+
use crate::style::{FlexboxContainerStyle, FlexboxItemStyle};
7+
#[cfg(feature = "grid")]
8+
use crate::style::{GridContainerStyle, GridItemStyle};
59

610
// Submodules
711
mod cache;
@@ -59,6 +63,63 @@ pub trait LayoutTree: PartialLayoutTree {
5963
fn get_final_layout_mut(&mut self, node_id: NodeId) -> &mut Layout;
6064
}
6165

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

0 commit comments

Comments
 (0)