mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
define RenderDyn, RenderBox
This commit is contained in:
parent
ee40fff168
commit
f24d5dfed0
7 changed files with 20 additions and 22 deletions
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue