compose_taffy/
traits.rs

1use compose_rt::{ComposeNode, NodeKey};
2use taffy::{Display, Layout, NodeId};
3
4pub trait IntoNodeId {
5    fn into_node_id(self) -> NodeId;
6}
7
8impl IntoNodeId for NodeKey {
9    #[inline(always)]
10    fn into_node_id(self) -> NodeId {
11        NodeId::from(self)
12    }
13}
14
15pub trait IntoNodeKey {
16    fn into_node_key(self) -> NodeKey;
17}
18
19impl IntoNodeKey for NodeId {
20    #[inline(always)]
21    fn into_node_key(self) -> NodeKey {
22        self.into()
23    }
24}
25
26pub trait TaffyConfig {
27    fn use_rounding(&self) -> bool;
28}
29
30pub trait TaffyNode: ComposeNode + 'static {
31    type NodeContext;
32
33    /// The style type representing the core container styles that all containers should have
34    /// Used when laying out the root node of a tree
35    type CoreContainerStyle: taffy::CoreStyle;
36
37    #[cfg(feature = "block_layout")]
38    /// The style type representing the CSS Block container's styles
39    type BlockContainerStyle<'a>: taffy::BlockContainerStyle
40    where
41        Self: 'a;
42
43    #[cfg(feature = "block_layout")]
44    /// The style type representing each CSS Block item's styles
45    type BlockItemStyle<'a>: taffy::BlockItemStyle
46    where
47        Self: 'a;
48
49    #[cfg(feature = "flexbox")]
50    /// The style type representing the Flexbox container's styles
51    type FlexboxContainerStyle<'a>: taffy::FlexboxContainerStyle
52    where
53        Self: 'a;
54
55    #[cfg(feature = "flexbox")]
56    /// The style type representing each Flexbox item's styles
57    type FlexboxItemStyle<'a>: taffy::FlexboxItemStyle
58    where
59        Self: 'a;
60
61    #[cfg(feature = "grid")]
62    /// The style type representing the CSS Grid container's styles
63    type GridContainerStyle<'a>: taffy::GridContainerStyle
64    where
65        Self: 'a;
66
67    #[cfg(feature = "grid")]
68    /// The style type representing each CSS Grid item's styles
69    type GridItemStyle<'a>: taffy::GridItemStyle
70    where
71        Self: 'a;
72
73    fn get_node_context(&self) -> Option<&Self::NodeContext>;
74    fn get_node_context_mut(&mut self) -> Option<&mut Self::NodeContext>;
75    fn get_node_context_mut_with_core_style(
76        &mut self,
77    ) -> (Option<&mut Self::NodeContext>, &Self::CoreContainerStyle);
78    fn get_display(&self) -> Display;
79    fn get_final_layout(&self) -> &Layout;
80    fn set_final_layout(&mut self, layout: &Layout);
81    fn get_unrounded_layout(&self) -> &Layout;
82    fn set_unrounded_layout(&mut self, layout: &Layout);
83    fn cache_get(
84        &self,
85        known_dimensions: taffy::Size<Option<f32>>,
86        available_space: taffy::Size<taffy::AvailableSpace>,
87        run_mode: taffy::RunMode,
88    ) -> Option<taffy::LayoutOutput>;
89    fn cache_store(
90        &mut self,
91        known_dimensions: taffy::Size<Option<f32>>,
92        available_space: taffy::Size<taffy::AvailableSpace>,
93        run_mode: taffy::RunMode,
94        layout_output: taffy::LayoutOutput,
95    );
96    fn cache_clear(&mut self);
97    fn get_core_container_style(&self) -> &Self::CoreContainerStyle;
98    #[cfg(feature = "block_layout")]
99    fn get_block_container_style(&self) -> Self::BlockContainerStyle<'_>;
100    #[cfg(feature = "block_layout")]
101    fn get_block_item_style(&self) -> Self::BlockItemStyle<'_>;
102    #[cfg(feature = "flexbox")]
103    fn get_flexbox_container_style(&self) -> Self::FlexboxContainerStyle<'_>;
104    #[cfg(feature = "flexbox")]
105    fn get_flexbox_item_style(&self) -> Self::FlexboxItemStyle<'_>;
106    #[cfg(feature = "grid")]
107    fn get_grid_container_style(&self) -> Self::GridContainerStyle<'_>;
108    #[cfg(feature = "grid")]
109    fn get_grid_item_style(&self) -> Self::GridItemStyle<'_>;
110}