diff --git a/edn/examples/edn01.rs b/edn/examples/edn01.rs index ebccfa0f..e8d46b7b 100644 --- a/edn/examples/edn01.rs +++ b/edn/examples/edn01.rs @@ -12,7 +12,7 @@ fn main () -> Usually<()> { pub struct Example; impl EdnLayout for &Example { - fn get_content <'a> (&'a self, sym: &'a str) -> Box> { + fn get_content <'a> (&'a self, sym: &'a str) -> RenderBox<'a, Tui> { Box::new(Thunk::new(move||if sym == ":hello" { "Hello world!" } else { "" })) } } diff --git a/edn/examples/edn02.rs b/edn/examples/edn02.rs index 183f8975..7b15bf64 100644 --- a/edn/examples/edn02.rs +++ b/edn/examples/edn02.rs @@ -12,7 +12,7 @@ fn main () -> Usually<()> { pub struct Example; impl EdnLayout for &Example { - fn get_content <'a> (&'a self, sym: &'a str) -> Box> { + fn get_content <'a> (&'a self, sym: &'a str) -> RenderBox<'a, Tui> { Box::new(Thunk::new(move||if sym == ":hello" { "Hello world!" } else { "" })) } } diff --git a/edn/src/edn_view.rs b/edn/src/edn_view.rs index ecc50407..488b8f3e 100644 --- a/edn/src/edn_view.rs +++ b/edn/src/edn_view.rs @@ -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 + Send + Sync + 'a; - pub type EdnCallback<'a, Engine, State> = - dyn Fn(&'a State)->Box> + Send + Sync + 'a; + dyn Fn(&'a State)-> RenderBox<'a, Engine> + Send + Sync + 'a; pub type EdnRenderCallback<'a, Engine, State> = Box>; @@ -16,7 +13,7 @@ pub trait EdnLayout { 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> { Box::new(()) } + fn get_content <'a> (&'a self, _sym: &'a str) -> RenderBox<'a, E> { Box::new(()) } } /// Renders from EDN source and context. diff --git a/engine/src/output/content.rs b/engine/src/output/content.rs index 746dcd28..cfec59c7 100644 --- a/engine/src/output/content.rs +++ b/engine/src/output/content.rs @@ -6,12 +6,7 @@ pub trait Content: 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 for Box + 'a> { - fn content (&self) -> impl Render { self } -} -impl<'a, E: Engine> Content for Box + Send + Sync + 'a> { - fn content (&self) -> impl Render { self } -} -impl Content for &(dyn Render + '_) { - fn content (&self) -> impl Render { self } +impl> Render 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) } } diff --git a/engine/src/output/render.rs b/engine/src/output/render.rs index 5ba5e1dc..1ab02953 100644 --- a/engine/src/output/render.rs +++ b/engine/src/output/render.rs @@ -4,9 +4,15 @@ use crate::*; pub trait Render: 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> Render 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 + 'a; +impl<'a, E: Engine> Content for &RenderDyn<'a, E> where Self: Sized { + fn content (&self) -> impl Render { self } +} +pub type RenderBox<'a, E: Engine> = Box>; +impl<'a, E: Engine> Content for RenderBox<'a, E> { + fn content (&self) -> impl Render { self } } diff --git a/src/groovebox.rs b/src/groovebox.rs index 8f248de0..20c83b4b 100644 --- a/src/groovebox.rs +++ b/src/groovebox.rs @@ -76,7 +76,7 @@ impl EdnLayout for Groovebox { _ => 0 } } - fn get_content <'a> (&'a self, item: &str) -> Box> { + 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])), diff --git a/src/lib.rs b/src/lib.rs index c39085a4..13b9bc1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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,