mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
big ass refactor (rip client)
This commit is contained in:
parent
94c1f83ef2
commit
8c3cf53c67
56 changed files with 2232 additions and 1891 deletions
42
src/view/layout/collect.rs
Normal file
42
src/view/layout/collect.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
pub enum Collected<'a> {
|
||||
Box(Box<dyn Render + 'a>),
|
||||
Ref(&'a (dyn Render + 'a)),
|
||||
None
|
||||
}
|
||||
|
||||
impl<'a> Render for Collected<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
match self {
|
||||
Self::Box(item) => (*item).render(buf, area),
|
||||
Self::Ref(item) => (*item).render(buf, area),
|
||||
Self::None => Ok(area),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Collector<'a>(pub Vec<Collected<'a>>);
|
||||
|
||||
impl<'a, R: Render + 'a> FnOnce<(R)> for Collector<'a> {
|
||||
type Output = ();
|
||||
extern "rust-call" fn call_once (self, (device, ): (R,)) -> Self::Output {
|
||||
self.add(widget.into_collected());
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Collector<'a> {
|
||||
pub fn collect (collect: impl Fn(&mut Collector<'a>)) -> Self {
|
||||
let mut items = Self(vec![]);
|
||||
collect(&mut items);
|
||||
items
|
||||
}
|
||||
fn add (mut self, widget: Collected<'a>) -> Self {
|
||||
self.0.push(widget);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Collection<'a, T, U> {
|
||||
fn add (self, widget: impl Render + 'a) -> Self;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue