refactor: collect collections

This commit is contained in:
🪞👃🪞 2024-09-06 23:14:27 +03:00
parent a52066f640
commit 1d21071c86
6 changed files with 78 additions and 82 deletions

View file

@ -44,3 +44,71 @@ impl<'a, E: Engine> Collect<'a, E> for Collection<'a, E> {
self
}
}
pub struct Layered<'a, E: Engine>(pub Collection<'a, E>);
impl<'a, E: Engine> Layered<'a, E> {
pub fn new () -> Self {
Self(Collection::new())
}
}
impl<'a, E: Engine> Collect<'a, E> for Layered<'a, E> {
fn add_box (mut self, item: Box<dyn Render<E> + 'a>) -> Self {
self.0 = self.0.add_box(item);
self
}
fn add_ref (mut self, item: &'a dyn Render<E>) -> Self {
self.0 = self.0.add_ref(item);
self
}
}
#[derive(Copy, Clone)]
pub enum Direction { Up, Down, Left, Right }
impl Direction {
pub fn is_down (&self) -> bool {
match self { Self::Down => true, _ => false }
}
pub fn is_right (&self) -> bool {
match self { Self::Right => true, _ => false }
}
}
pub struct Split<'a, E: Engine> {
pub items: Collection<'a, E>,
pub direction: Direction,
pub focus: Option<usize>
}
impl<'a, E: Engine> Split<'a, E> {
pub fn new (direction: Direction) -> Self {
Self {
items: Collection::new(),
direction,
focus: None
}
}
pub fn down () -> Self {
Self::new(Direction::Down)
}
pub fn right () -> Self {
Self::new(Direction::Right)
}
pub fn focus (mut self, focus: Option<usize>) -> Self {
self.focus = focus;
self
}
}
impl<'a, E: Engine> Collect<'a, E> for Split<'a, E> {
fn add_box (mut self, item: Box<dyn Render<E> + 'a>) -> Self {
self.items = self.items.add_box(item);
self
}
fn add_ref (mut self, item: &'a dyn Render<E>) -> Self {
self.items = self.items.add_ref(item);
self
}
}