output: more big refactors

This commit is contained in:
🪞👃🪞 2025-09-07 12:34:30 +03:00
parent 194f2f9874
commit 5e6338fad8
68 changed files with 1604 additions and 1016 deletions

40
output/src/content.rs Normal file
View file

@ -0,0 +1,40 @@
use crate::*;
/// Composable renderable with static dispatch.
pub trait Content<E: Out>: Sized {
/// Return opaque [Draw]able.
fn content (&self) -> impl Draw<E> + Layout<E> + '_ { () }
}
/// The platonic ideal unit of [Content]:
/// total emptiness at dead center (e=1vg^sqrt(-1))
impl<E: Out> Content<E> for () {}
impl<E: Out, T: Draw<E> + Layout<E>> Content<E> for fn()->T {
fn content (&self) -> impl Draw<E> + Layout<E> + '_ {
self()
}
}
/// Implement composable content for a struct.
#[macro_export] macro_rules! content {
// Implement for all [Out]s.
(|$self:ident:$Struct:ty| $content:expr) => {
impl<E: Out> Content<E> for $Struct {
fn content (&$self) -> impl Draw<E> + Layout<E> + '_ { Some($content) }
}
};
// Implement for specific [Out].
($Out:ty:|
$self:ident:
$Struct:ident$(<$($($L:lifetime)? $($T:ident)? $(:$Trait:path)?),+>)?
|$content:expr) => {
impl $(<$($($L)? $($T)? $(:$Trait)?),+>)? Content<$Out>
for $Struct $(<$($($L)? $($T)?),+>)? {
fn content (&$self) -> impl Draw<$Out> + Layout<$Out> + '_ { $content }
}
};
}