mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
Rust
use crate::*;
|
|
|
|
#[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
|
|
}
|
|
}
|