mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
refactor: collect collections
This commit is contained in:
parent
a52066f640
commit
1d21071c86
6 changed files with 78 additions and 82 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue