mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
define RenderDyn, RenderBox
This commit is contained in:
parent
ee40fff168
commit
f24d5dfed0
7 changed files with 20 additions and 22 deletions
|
|
@ -12,7 +12,7 @@ fn main () -> Usually<()> {
|
|||
pub struct Example;
|
||||
|
||||
impl EdnLayout<Tui> for &Example {
|
||||
fn get_content <'a> (&'a self, sym: &'a str) -> Box<EdnRender<'a, Tui>> {
|
||||
fn get_content <'a> (&'a self, sym: &'a str) -> RenderBox<'a, Tui> {
|
||||
Box::new(Thunk::new(move||if sym == ":hello" { "Hello world!" } else { "" }))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ fn main () -> Usually<()> {
|
|||
pub struct Example;
|
||||
|
||||
impl EdnLayout<Tui> for &Example {
|
||||
fn get_content <'a> (&'a self, sym: &'a str) -> Box<EdnRender<'a, Tui>> {
|
||||
fn get_content <'a> (&'a self, sym: &'a str) -> RenderBox<'a, Tui> {
|
||||
Box::new(Thunk::new(move||if sym == ":hello" { "Hello world!" } else { "" }))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
use crate::*;
|
||||
use std::marker::PhantomData;
|
||||
use ::tek_layout::{*, tek_engine::{Usually, Content, Render, Engine, Thunk}};
|
||||
use ::tek_layout::{*, tek_engine::{Usually, Content, Render, RenderBox, Engine, Thunk}};
|
||||
use EdnItem::*;
|
||||
|
||||
pub type EdnRender<'a, Engine> =
|
||||
dyn Render<Engine> + Send + Sync + 'a;
|
||||
|
||||
pub type EdnCallback<'a, Engine, State> =
|
||||
dyn Fn(&'a State)->Box<EdnRender<'a, Engine>> + Send + Sync + 'a;
|
||||
dyn Fn(&'a State)-> RenderBox<'a, Engine> + Send + Sync + 'a;
|
||||
|
||||
pub type EdnRenderCallback<'a, Engine, State> =
|
||||
Box<EdnCallback<'a, Engine, State>>;
|
||||
|
|
@ -16,7 +13,7 @@ pub trait EdnLayout<E: Engine> {
|
|||
fn get_bool (&self, _sym: &str) -> bool { false }
|
||||
fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() }
|
||||
fn get_usize (&self, _sym: &str) -> usize { 0 }
|
||||
fn get_content <'a> (&'a self, _sym: &'a str) -> Box<EdnRender<'a, E>> { Box::new(()) }
|
||||
fn get_content <'a> (&'a self, _sym: &'a str) -> RenderBox<'a, E> { Box::new(()) }
|
||||
}
|
||||
|
||||
/// Renders from EDN source and context.
|
||||
|
|
|
|||
|
|
@ -6,12 +6,7 @@ pub trait Content<E: Engine>: Send + Sync + Sized {
|
|||
fn layout (&self, area: E::Area) -> E::Area { self.content().layout(area) }
|
||||
fn render (&self, output: &mut E::Output) { self.content().render(output) }
|
||||
}
|
||||
impl<'a, E: Engine> Content<E> for Box<dyn Render<E> + 'a> {
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
}
|
||||
impl<'a, E: Engine> Content<E> for Box<dyn Render<E> + Send + Sync + 'a> {
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
}
|
||||
impl<E: Engine> Content<E> for &(dyn Render<E> + '_) {
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
impl<E: Engine, C: Content<E>> Render<E> for C {
|
||||
fn layout (&self, area: E::Area) -> E::Area { Content::layout(self, area) }
|
||||
fn render (&self, output: &mut E::Output) { Content::render(self, output) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,15 @@ use crate::*;
|
|||
pub trait Render<E: Engine>: Send + Sync {
|
||||
fn layout (&self, area: E::Area) -> E::Area;
|
||||
fn render (&self, output: &mut E::Output);
|
||||
fn boxed <'a> (self) -> RenderBox<'a, E> where Self: Sized + 'a {
|
||||
Box::new(self) as RenderBox<'a, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, C: Content<E>> Render<E> for C {
|
||||
fn layout (&self, area: E::Area) -> E::Area { Content::layout(self, area) }
|
||||
fn render (&self, output: &mut E::Output) { Content::render(self, output) }
|
||||
pub type RenderDyn<'a, Engine> = dyn Render<Engine> + 'a;
|
||||
impl<'a, E: Engine> Content<E> for &RenderDyn<'a, E> where Self: Sized {
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
}
|
||||
pub type RenderBox<'a, E: Engine> = Box<RenderDyn<'a, E>>;
|
||||
impl<'a, E: Engine> Content<E> for RenderBox<'a, E> {
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl EdnLayout<Tui> for Groovebox {
|
|||
_ => 0
|
||||
}
|
||||
}
|
||||
fn get_content <'a> (&'a self, item: &str) -> Box<EdnRender<'a, Tui>> {
|
||||
fn get_content <'a> (&'a self, item: &str) -> RenderBox<'a, Tui> {
|
||||
use EdnItem::*;
|
||||
match item {
|
||||
":input-meter-l" => Box::new(Meter("L/", self.sampler.input_meter[0])),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub(crate) use ::tek_tui::{
|
|||
tek_engine::{
|
||||
from,
|
||||
Usually, Perhaps,
|
||||
Output, Content, Render, Thunk, render, Engine, Size, Area,
|
||||
Output, Content, Render, RenderBox, Thunk, render, Engine, Size, Area,
|
||||
Input, handle, Handle, command, Command, input_to_command, InputToCommand, keymap, EventMap,
|
||||
},
|
||||
Tui,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue