more esoteric with the docs; center all by default; genericity without subject doesnt compile lol

This commit is contained in:
🪞👃🪞 2025-01-01 01:51:45 +01:00
parent f7e6449324
commit 059ff2ca79
5 changed files with 44 additions and 37 deletions

View file

@ -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...

View file

@ -21,10 +21,10 @@ impl<E: Engine, T: Content<E>> Align<E, T> {
impl<E: Engine, T: Content<E>> Content<E> for Align<E, T> {
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())
}
}

View file

@ -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
}

View file

@ -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<E: Engine, T: Content<E>> {
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), ]