#[cfg(feature = "unstable")]
use crate::BlockLayouter;
use crate::{FlowLayouter, FragmentNode, ItemFragment, LayoutNode};
#[derive(Debug)]
pub enum LayoutChild {
Node(Box<LayoutNode>),
Fragment(FragmentNode),
Object(Box<dyn FlowLayouter>),
#[cfg(feature = "unstable")]
Custom(Box<dyn BlockLayouter>),
}
impl LayoutChild {
pub fn node(&self) -> Option<&LayoutNode> {
match self {
LayoutChild::Node(n) => Some(n),
_ => None,
}
}
pub fn node_mut(&mut self) -> Option<&mut LayoutNode> {
match self {
LayoutChild::Node(n) => Some(n),
_ => None,
}
}
pub fn fragment(&self) -> Option<&FragmentNode> {
match self {
LayoutChild::Fragment(f) => Some(f),
_ => None,
}
}
pub fn fragment_mut(&mut self) -> Option<&mut FragmentNode> {
match self {
LayoutChild::Fragment(f) => Some(f),
_ => None,
}
}
pub fn object(&self) -> Option<&dyn FlowLayouter> {
match self {
LayoutChild::Object(o) => Some(&**o),
_ => None,
}
}
#[cfg(feature = "unstable")]
pub fn custom(&self) -> Option<&Box<dyn BlockLayouter>> {
match self {
LayoutChild::Custom(c) => Some(c),
_ => None,
}
}
#[cfg(feature = "unstable")]
pub fn custom_mut(&mut self) -> Option<&mut Box<dyn BlockLayouter>> {
match self {
LayoutChild::Custom(c) => Some(c),
_ => None,
}
}
}
impl From<LayoutNode> for LayoutChild {
fn from(node: LayoutNode) -> Self {
LayoutChild::Node(Box::new(node))
}
}
impl From<FragmentNode> for LayoutChild {
fn from(fragment: FragmentNode) -> Self {
LayoutChild::Fragment(fragment)
}
}
impl From<ItemFragment> for LayoutChild {
fn from(value: ItemFragment) -> Self {
LayoutChild::Fragment(FragmentNode::new(value))
}
}