macro_rules! element_with_children {
($el:ty) => {
impl ElementWithChildren for $el {
#[inline(always)]
fn add_child(&mut self, child: impl Into<Box<dyn Element>>) -> Result<(), crate::error::LintuiniError>{
self.children.push(child.into());
self.regenerate_layout();
Ok(())
}
#[inline(always)]
fn children(&self) -> &[Box<dyn Element>] {
self.children.as_slice()
}
#[inline(always)]
fn children_mut(&mut self) -> &mut [Box<dyn Element>] {
self.children.as_mut_slice()
}
}
}
}
pub(crate) use element_with_children;
macro_rules! basic_config_methods {
($el:ty) => {
impl $el {
#[inline(always)]
pub fn new() -> Self {
<$el>::default()
}
#[inline(always)]
pub fn constraint(&mut self, constraint: ratatui_core::layout::Constraint) -> &mut Self {
self.constraint = constraint;
self
}
// beware the owned self!
#[inline(always)]
pub fn direction(mut self, direction: ratatui_core::layout::Direction) -> Self {
self.layout = self.layout.direction(direction);
self.regenerate_layout();
self
}
pub fn regenerate_layout(&mut self) -> &mut Self {
if self.children.len() == 0 { return self; }
self.layout = self.layout.clone().constraints(
self.children
.iter()
.map(|el| el.constraint())
);
self
}
}
}
}
pub(crate) use basic_config_methods;