From 059ff2ca79a9bbd00b51e929377967746b3d26b3 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 1 Jan 2025 01:51:45 +0100 Subject: [PATCH] more esoteric with the docs; center all by default; genericity without subject doesnt compile lol --- layout/README.md | 36 ++++++++++++++++++--------------- layout/src/align.rs | 4 ++-- layout/src/lib.rs | 10 +++++---- layout/src/transform_xy_unit.rs | 24 +++++++++++----------- src/groovebox.rs | 7 ++++--- 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/layout/README.md b/layout/README.md index 82959db0..80ebcad4 100644 --- a/layout/README.md +++ b/layout/README.md @@ -2,20 +2,24 @@ this crate exposes several layout operators which work entirely in unsigned coordinates -and are generic over `tek_engine::Engine`. +and are generic over `tek_engine::Engine` +and `tek_engine::Content`. chiefly, they +are not dependent on rendering framework. -* `Fill` makes the content's dimension equal to the container's. -* `Fixed` assigns a fixed dimension to its content. -* `Shrink` reduces the dimension of the content -* `Expand` increases the dimension of the content -* `Min` enforces minimum dimension for the content -* `Max` enforces maximum dimension for the content -* `Push` moves the content in the positive direction -* `Pull` moves the content in the negative direction -* `Margin` grows each dimension from both ends -* `Padding` shrinks each dimension from both ends -* `Align` pins the content along an axis of the container -* `When` renders a content conditionally -* `Either` alternates between two contents -* `Map` transforms each content -* `Reduce` transforms all contents into one +* `Fill` is to make the content's dimension equal to the container's. +* `Fixed` is to assign a fixed dimension to its content. +* `Shrink`/`Expand` are to change the dimension of the content +* `Min`/`Max` are to constrain the dimension of the content +* `Push`/`Pull` are to move the content along the axis +* `Margin`/`Padding` are to change the dimension proportionally +* `Align` is to pin the content along the axis of the container +* `When` is to render content conditionally +* `Either` is to alternates between contents +* `Map` is to transform each content +* `Reduce` is to transform all contents into one +* and, finally, `Bsp` is to put 2 where there was 1. + +**todo.** and then you're like, +"but why are they generic over E in the first place +and not, say, over E::Unit? that might even free up +some space to implement for non-uint cosmologies... diff --git a/layout/src/align.rs b/layout/src/align.rs index 750ea75d..d63ca324 100644 --- a/layout/src/align.rs +++ b/layout/src/align.rs @@ -21,10 +21,10 @@ impl> Align { impl> Content for Align { fn layout (&self, outer: E::Area) -> E::Area { - align_areas(self.0, outer.xywh(), Content::area(&self.content(), outer).xywh()).into() + align_areas(self.0, outer.xywh(), Content::layout(&self.content(), outer).xywh()).into() } fn render (&self, render: &mut E::Output) { - render.place(self.area(render.area()), &self.content()) + render.place(self.layout(render.area()), &self.content()) } } diff --git a/layout/src/lib.rs b/layout/src/lib.rs index bead884a..a8e27425 100644 --- a/layout/src/lib.rs +++ b/layout/src/lib.rs @@ -13,9 +13,11 @@ pub(crate) use ::tek_engine::*; pub(crate) use std::marker::PhantomData; #[cfg(test)] #[test] fn test_layout () -> Usually<()> { + let area: [u16;4] = [10, 10, 20, 20]; + let unit = (); + //assert_eq!(().layout(area), [15, 15, 0, 0]); // should be independent over E, isn't + assert_eq!(Fill::x(()).layout(area), [10, 15, 20, 0]); + assert_eq!(Fill::y(()).layout(area), [15, 10, 0, 20]); + assert_eq!(Fill::xy(()).layout(area), area); Ok(()) } - -#[cfg(test)] #[test] fn test_bsp () { - // TODO -} diff --git a/layout/src/transform_xy_unit.rs b/layout/src/transform_xy_unit.rs index 6f7984a1..e2149d8d 100644 --- a/layout/src/transform_xy_unit.rs +++ b/layout/src/transform_xy_unit.rs @@ -3,7 +3,7 @@ use crate::*; /// Defines an enum that parametrically transforms its content /// along either the X axis, the Y axis, or both. macro_rules! transform_xy_unit { - (|$self:ident : $Enum:ident, $to:ident|$area:expr) => { + (|$self:ident : $Enum:ident, $to:ident|$layout:expr) => { pub enum $Enum> { X(E::Unit, T), Y(E::Unit, T), XY(E::Unit, E::Unit, T), } @@ -34,15 +34,15 @@ macro_rules! transform_xy_unit { Self::XY(_, _, content) => content, }) } - fn area (&$self, $to: E::Area) -> E::Area { - $area.into() + fn layout (&$self, $to: E::Area) -> E::Area { + $layout.into() } } } } transform_xy_unit!(|self: Fixed, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); match self { Self::X(fw, _) => [area.x(), area.y(), *fw, area.h()], Self::Y(fh, _) => [area.x(), area.y(), area.w(), *fh], @@ -51,17 +51,17 @@ transform_xy_unit!(|self: Fixed, area|{ }); transform_xy_unit!(|self: Shrink, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); [area.x(), area.y(), area.w().minus(self.dx()), area.h().minus(self.dy())] }); transform_xy_unit!(|self: Expand, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); [area.x(), area.y(), area.w() + self.dx(), area.h() + self.dy()] }); transform_xy_unit!(|self: Min, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); match self { Self::X(mw, _) => [area.x(), area.y(), area.w().max(*mw), area.h()], Self::Y(mh, _) => [area.x(), area.y(), area.w(), area.h().max(*mh)], @@ -69,7 +69,7 @@ transform_xy_unit!(|self: Min, area|{ }}); transform_xy_unit!(|self: Max, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); match self { Self::X(mw, _) => [area.x(), area.y(), area.w().min(*mw), area.h()], Self::Y(mh, _) => [area.x(), area.y(), area.w(), area.h().min(*mh)], @@ -77,24 +77,24 @@ transform_xy_unit!(|self: Max, area|{ }}); transform_xy_unit!(|self: Push, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); [area.x() + self.dx(), area.y() + self.dy(), area.w(), area.h()] }); transform_xy_unit!(|self: Pull, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); [area.x().minus(self.dx()), area.y().minus(self.dy()), area.w(), area.h()] }); transform_xy_unit!(|self: Margin, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); let dx = self.dx(); let dy = self.dy(); [area.x().minus(dx), area.y().minus(dy), area.w() + dy + dy, area.h() + dy + dy] }); transform_xy_unit!(|self: Padding, area|{ - let area = self.content().area(area); + let area = self.content().layout(area); let dx = self.dx(); let dy = self.dy(); [area.x() + dx, area.y() + dy, area.w().minus(dy + dy), area.h().minus(dy + dy), ] diff --git a/src/groovebox.rs b/src/groovebox.rs index 81d7138d..ff1f1bc8 100644 --- a/src/groovebox.rs +++ b/src/groovebox.rs @@ -128,9 +128,10 @@ render!(Tui: (self: Groovebox) => { PhraseSelector::play_phrase(&self.player), PhraseSelector::next_phrase(&self.player), ))); - let pool = PoolView(&self.pool); - let with_pool = move|x|Bsp::w(Fixed::x(pool_w, Pull::y(1, Fill::y(Align::e(pool)))), x); - with_pool(col!(transport, selector)) + "tabula rasa" + //let pool = PoolView(&self.pool); + //let with_pool = move|x|Bsp::w(Fixed::x(pool_w, Pull::y(1, Fill::y(Align::e(pool)))), x); + //with_pool(col!(transport, selector)) //selector //let sampler = move|x|Bsp::e( //Fixed::x(sampler_w, Fill::xy(col!(