mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
46 lines
1.8 KiB
Rust
46 lines
1.8 KiB
Rust
use crate::*;
|
|
/// Build a [Render]able out of other [Render]ables,
|
|
/// then apply optional custom render/layout on top.
|
|
pub trait Content<E: Output>: Send + Sync + Sized {
|
|
fn content (&self) -> impl Render<E> { () }
|
|
fn layout (&self, area: E::Area) -> E::Area { self.content().layout(area) }
|
|
fn render (&self, output: &mut E) { self.content().render(output) }
|
|
}
|
|
impl<E: Output, C: Content<E>> Content<E> for &C {
|
|
fn content (&self) -> impl Render<E> { (*self).content() }
|
|
fn layout (&self, area: E::Area) -> E::Area { (*self).layout(area) }
|
|
fn render (&self, output: &mut E) { (*self).render(output) }
|
|
}
|
|
/// The platonic ideal unit of [Content]: total emptiness at dead center.
|
|
impl<E: Output> Content<E> for () {
|
|
fn layout (&self, area: E::Area) -> E::Area { area.center().to_area_pos().into() }
|
|
fn render (&self, _: &mut E) {}
|
|
}
|
|
impl<E: Output, T: Content<E>> Content<E> for Option<T> {
|
|
fn content (&self) -> impl Render<E> {
|
|
self.as_ref()
|
|
}
|
|
fn layout (&self, area: E::Area) -> E::Area {
|
|
self.as_ref()
|
|
.map(|content|content.layout(area))
|
|
.unwrap_or([0.into(), 0.into(), 0.into(), 0.into(),].into())
|
|
}
|
|
fn render (&self, output: &mut E) {
|
|
self.as_ref()
|
|
.map(|content|content.render(output));
|
|
}
|
|
}
|
|
//impl<E: Output, T: Content<E>, E: Content<E>> Content<E> for Option<T> {
|
|
//fn content (&self) -> impl Render<E> {
|
|
//self.as_ref()
|
|
//}
|
|
//fn layout (&self, area: E::Area) -> E::Area {
|
|
//self.as_ref()
|
|
//.map(|content|content.layout(area))
|
|
//.unwrap_or([0.into(), 0.into(), 0.into(), 0.into(),].into())
|
|
//}
|
|
//fn render (&self, output: &mut E) {
|
|
//self.as_ref()
|
|
//.map(|content|content.render(output));
|
|
//}
|
|
//}
|