Skip to content

Commit

Permalink
Add algorithm-specific PartialLayoutTree traits
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Oct 22, 2023
1 parent 9d39190 commit 11e7840
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion src/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! 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.

use crate::geometry::{Line, Size};
use crate::style::{AvailableSpace, Style};
use crate::style::{
AvailableSpace, CoreStyle, FlexboxContainerStyle, FlexboxItemStyle, GridContainerStyle, GridItemStyle, Style,
};

// Submodules
mod cache;
Expand Down Expand Up @@ -59,6 +61,63 @@ pub trait LayoutTree: PartialLayoutTree {
fn get_final_layout_mut(&mut self, node_id: NodeId) -> &mut Layout;
}

#[cfg(feature = "flexbox")]
/// Extends [`PartialLayoutTree`] with getters for the styles required for Flexbox layout
pub trait FlexboxPartialLayoutTree: PartialLayoutTree {
/// The style type representing the Flexbox container's styles
type ContainerStyle<'a>: FlexboxContainerStyle
where
Self: 'a;
/// The style type representing each Flexbox item's styles
type ItemStyle<'a>: FlexboxItemStyle
where
Self: 'a;

/// Get the container's styles
fn get_container_style<'a>(&'a self, node_id: NodeId) -> Self::ContainerStyle<'a>;

/// Get the child's styles
fn get_child_style<'a>(&'a self, child_node_id: NodeId) -> Self::ItemStyle<'a>;
}

#[cfg(feature = "grid")]
/// Extends [`PartialLayoutTree`] with getters for the styles required for CSS Grid layout
pub trait GridPartialLayoutTree: PartialLayoutTree {
/// The style type representing the CSS Grid container's styles
type ContainerStyle<'a>: GridContainerStyle
where
Self: 'a;
/// The style type representing each CSS Grid item's styles
type ItemStyle<'a>: GridItemStyle
where
Self: 'a;

/// Get the container's styles
fn get_container_style<'a>(&'a self, node_id: NodeId) -> Self::ContainerStyle<'a>;

/// Get the child's styles
fn get_child_style<'a>(&'a self, child_node_id: NodeId) -> Self::ItemStyle<'a>;
}

#[cfg(feature = "block_layout")]
/// Extends [`PartialLayoutTree`] with getters for the styles required for CSS Block layout
pub trait BlockPartialLayoutTree: PartialLayoutTree {
/// The style type representing the CSS Block container's styles
type ContainerStyle<'a>: CoreStyle
where
Self: 'a;
/// The style type representing each CSS Block item's styles
type ItemStyle<'a>: CoreStyle
where
Self: 'a;

/// Get the container's styles
fn get_container_style<'a>(&'a self, node_id: NodeId) -> Self::ContainerStyle<'a>;

/// Get the child's styles
fn get_child_style<'a>(&'a self, child_node_id: NodeId) -> Self::ItemStyle<'a>;
}

/// A private trait which allows us to add extra convenience methods to types which implement
/// LayoutTree without making those methods public.
pub(crate) trait PartialLayoutTreeExt: PartialLayoutTree {
Expand Down

0 comments on commit 11e7840

Please sign in to comment.