'and then not have to worry about layout, ever'

This commit is contained in:
🪞👃🪞 2024-12-31 23:58:51 +01:00
parent 21741ebc52
commit f7e6449324
8 changed files with 74 additions and 74 deletions

View file

@ -22,27 +22,32 @@ pub trait Content<E: Engine>: Send + Sync {
fn content (&self) -> impl Content<E> {
()
}
fn area (&self, area: E::Area) -> E::Area {
self.content().area(area)
fn layout (&self, area: E::Area) -> E::Area {
self.content().layout(area)
}
fn render (&self, output: &mut E::Output) {
self.content().render(output)
output.place(self.layout(output.area()), &self.content())
}
}
/// The platonic ideal item of content: emptiness at dead center.
impl<E: Engine> Content<E> for () {
fn area (&self, _: E::Area) -> E::Area {
[0.into(), 0.into(), 0.into(), 0.into()].into()
fn layout (&self, area: E::Area) -> E::Area {
let [x, y, w, h] = area.xywh();
let x = x + w / 2.into();
let y = y + h / 2.into();
[x, y, 0.into(), 0.into()].into()
}
fn render (&self, _: &mut E::Output) {
}
fn render (&self, _: &mut E::Output) {}
}
impl<E: Engine, T: Content<E>> Content<E> for &T {
fn content (&self) -> impl Content<E> {
(*self).content()
}
fn area (&self, area: E::Area) -> E::Area {
(*self).area(area)
fn layout (&self, area: E::Area) -> E::Area {
(*self).layout(area)
}
fn render (&self, output: &mut E::Output) {
(*self).render(output)
@ -54,9 +59,9 @@ impl<E: Engine, T: Content<E>> Content<E> for Option<T> {
self.as_ref()
.map(|content|content.content())
}
fn area (&self, area: E::Area) -> E::Area {
fn layout (&self, area: E::Area) -> E::Area {
self.as_ref()
.map(|content|content.area(area))
.map(|content|content.layout(area))
.unwrap_or([0.into(), 0.into(), 0.into(), 0.into(),].into())
}
fn render (&self, output: &mut E::Output) {