mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-11 22:26:44 +01:00
wip: generic render
This commit is contained in:
parent
7bd2a70e85
commit
fcd2d16de9
12 changed files with 314 additions and 351 deletions
|
|
@ -1,29 +1,30 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct Layered<'a>(Collection<'a>);
|
||||
pub struct Layered<'a, T, U>(Collection<'a, T, U>);
|
||||
|
||||
impl<'a> Layered<'a> {
|
||||
impl<'a, T, U> Layered<'a, T, U> {
|
||||
pub fn new () -> Self {
|
||||
Self(Collection::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render for Layered<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
for layer in self.0.0.iter() {
|
||||
layer.render(buf, area)?;
|
||||
}
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Collect<'a> for Layered<'a> {
|
||||
fn add_box (mut self, item: Box<dyn Render + 'a>) -> Self {
|
||||
impl<'a, T, U> Collect<'a, T, U> for Layered<'a, T, U> {
|
||||
fn add_box (mut self, item: Box<dyn Render<T, U> + 'a>) -> Self {
|
||||
self.0 = self.0.add_box(item);
|
||||
self
|
||||
}
|
||||
fn add_ref (mut self, item: &'a dyn Render) -> Self {
|
||||
fn add_ref (mut self, item: &'a dyn Render<T, U>) -> Self {
|
||||
self.0 = self.0.add_ref(item);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> Render<TuiOutput<'b>, Rect> for Layered<'a, TuiOutput<'b>, Rect> {
|
||||
fn render (&self, to: &mut TuiOutput<'b>) -> Perhaps<Rect> {
|
||||
let area = to.area;
|
||||
for layer in self.0.0.iter() {
|
||||
layer.render(to)?;
|
||||
}
|
||||
Ok(Some(area))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue