mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
wip: tui cleanup
This commit is contained in:
parent
df3dac183e
commit
14d619a10a
17 changed files with 345 additions and 306 deletions
46
crates/tek_core/src/component/collect.rs
Normal file
46
crates/tek_core/src/component/collect.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use crate::*;
|
||||
|
||||
pub enum Collected<'a, E: Engine> {
|
||||
Box(Box<dyn Render<E> + 'a>),
|
||||
Ref(&'a (dyn Render<E> + 'a)),
|
||||
}
|
||||
|
||||
impl<'a, E: Engine> Render<E> for Collected<'a, E> {
|
||||
fn render (&self, to: &mut E) -> Perhaps<E::Rendered> {
|
||||
match self {
|
||||
Self::Box(item) => (*item).render(to),
|
||||
Self::Ref(item) => (*item).render(to),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Collection<'a, E: Engine>(
|
||||
pub Vec<Collected<'a, E>>
|
||||
);
|
||||
|
||||
impl<'a, E: Engine> Collection<'a, E> {
|
||||
pub fn new () -> Self {
|
||||
Self(vec![])
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Collect<'a, E: Engine> {
|
||||
fn add_box (self, item: Box<dyn Render<E> + 'a>) -> Self;
|
||||
fn add_ref (self, item: &'a dyn Render<E>) -> Self;
|
||||
fn add <R: Render<E> + Sized + 'a> (self, item: R) -> Self
|
||||
where Self: Sized
|
||||
{
|
||||
self.add_box(Box::new(item))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E: Engine> Collect<'a, E> for Collection<'a, E> {
|
||||
fn add_box (mut self, item: Box<dyn Render<E> + 'a>) -> Self {
|
||||
self.0.push(Collected::Box(item));
|
||||
self
|
||||
}
|
||||
fn add_ref (mut self, item: &'a dyn Render<E>) -> Self {
|
||||
self.0.push(Collected::Ref(item));
|
||||
self
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue