ohh why did i begin this refactor. e57

This commit is contained in:
🪞👃🪞 2024-12-31 13:18:12 +01:00
parent 83eb9dd2fa
commit 49adf34b02
6 changed files with 46 additions and 41 deletions

View file

@ -18,29 +18,30 @@ pub trait Output<E: Engine> {
}
pub trait Content<E: Engine>: Send + Sync {
fn content (&self) -> Option<impl Content<E>> {
None::<()>
fn content (&self) -> impl Content<E> {
()
}
fn area (&self, area: E::Area) -> E::Area {
if let Some(content) = self.content() {
content.area(area)
} else {
[0.into(), 0.into(), 0.into(), 0.into()].into()
}
self.content().area(area)
}
fn render (&self, output: &mut E::Output) {
if let Some(content) = self.content() {
output.place(self.area(output.area()), &content)
}
self.content().render(output)
}
}
impl<E: Engine> Content<E> for () {}
impl<E: Engine> Content<E> for () {
fn area (&self, area: E::Area) -> E::Area {
[0.into(), 0.into(), 0.into(), 0.into()].into()
}
fn render (&self, output: &mut E::Output) {}
}
impl<E: Engine, T: Content<E>> Content<E> for &T {}
impl<E: Engine, T: Content<E>> Content<E> for Option<T> {}
impl<E: Engine, T: Content<E>> Content<E> for Vec<T> {}
#[macro_export] macro_rules! render {
(($self:ident:$Struct:ty) => $content:expr) => {
impl <E: Engine> Content<E> for $Struct {