mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
more esoteric with the docs; center all by default; genericity without subject doesnt compile lol
This commit is contained in:
parent
f7e6449324
commit
059ff2ca79
5 changed files with 44 additions and 37 deletions
|
|
@ -2,20 +2,24 @@
|
||||||
|
|
||||||
this crate exposes several layout operators
|
this crate exposes several layout operators
|
||||||
which work entirely in unsigned coordinates
|
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.
|
* `Fill` is to make the content's dimension equal to the container's.
|
||||||
* `Fixed` assigns a fixed dimension to its content.
|
* `Fixed` is to assign a fixed dimension to its content.
|
||||||
* `Shrink` reduces the dimension of the content
|
* `Shrink`/`Expand` are to change the dimension of the content
|
||||||
* `Expand` increases the dimension of the content
|
* `Min`/`Max` are to constrain the dimension of the content
|
||||||
* `Min` enforces minimum dimension for the content
|
* `Push`/`Pull` are to move the content along the axis
|
||||||
* `Max` enforces maximum dimension for the content
|
* `Margin`/`Padding` are to change the dimension proportionally
|
||||||
* `Push` moves the content in the positive direction
|
* `Align` is to pin the content along the axis of the container
|
||||||
* `Pull` moves the content in the negative direction
|
* `When` is to render content conditionally
|
||||||
* `Margin` grows each dimension from both ends
|
* `Either` is to alternates between contents
|
||||||
* `Padding` shrinks each dimension from both ends
|
* `Map` is to transform each content
|
||||||
* `Align` pins the content along an axis of the container
|
* `Reduce` is to transform all contents into one
|
||||||
* `When` renders a content conditionally
|
* and, finally, `Bsp` is to put 2 where there was 1.
|
||||||
* `Either` alternates between two contents
|
|
||||||
* `Map` transforms each content
|
**todo.** and then you're like,
|
||||||
* `Reduce` transforms all contents into one
|
"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...
|
||||||
|
|
|
||||||
|
|
@ -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> {
|
impl<E: Engine, T: Content<E>> Content<E> for Align<E, T> {
|
||||||
fn layout (&self, outer: E::Area) -> E::Area {
|
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) {
|
fn render (&self, render: &mut E::Output) {
|
||||||
render.place(self.area(render.area()), &self.content())
|
render.place(self.layout(render.area()), &self.content())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,11 @@ pub(crate) use ::tek_engine::*;
|
||||||
pub(crate) use std::marker::PhantomData;
|
pub(crate) use std::marker::PhantomData;
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_layout () -> Usually<()> {
|
#[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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_bsp () {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::*;
|
||||||
/// Defines an enum that parametrically transforms its content
|
/// Defines an enum that parametrically transforms its content
|
||||||
/// along either the X axis, the Y axis, or both.
|
/// along either the X axis, the Y axis, or both.
|
||||||
macro_rules! transform_xy_unit {
|
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>> {
|
pub enum $Enum<E: Engine, T: Content<E>> {
|
||||||
X(E::Unit, T), Y(E::Unit, T), XY(E::Unit, E::Unit, T),
|
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,
|
Self::XY(_, _, content) => content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn area (&$self, $to: E::Area) -> E::Area {
|
fn layout (&$self, $to: E::Area) -> E::Area {
|
||||||
$area.into()
|
$layout.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transform_xy_unit!(|self: Fixed, area|{
|
transform_xy_unit!(|self: Fixed, area|{
|
||||||
let area = self.content().area(area);
|
let area = self.content().layout(area);
|
||||||
match self {
|
match self {
|
||||||
Self::X(fw, _) => [area.x(), area.y(), *fw, area.h()],
|
Self::X(fw, _) => [area.x(), area.y(), *fw, area.h()],
|
||||||
Self::Y(fh, _) => [area.x(), area.y(), area.w(), *fh],
|
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|{
|
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())]
|
[area.x(), area.y(), area.w().minus(self.dx()), area.h().minus(self.dy())]
|
||||||
});
|
});
|
||||||
|
|
||||||
transform_xy_unit!(|self: Expand, area|{
|
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()]
|
[area.x(), area.y(), area.w() + self.dx(), area.h() + self.dy()]
|
||||||
});
|
});
|
||||||
|
|
||||||
transform_xy_unit!(|self: Min, area|{
|
transform_xy_unit!(|self: Min, area|{
|
||||||
let area = self.content().area(area);
|
let area = self.content().layout(area);
|
||||||
match self {
|
match self {
|
||||||
Self::X(mw, _) => [area.x(), area.y(), area.w().max(*mw), area.h()],
|
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)],
|
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|{
|
transform_xy_unit!(|self: Max, area|{
|
||||||
let area = self.content().area(area);
|
let area = self.content().layout(area);
|
||||||
match self {
|
match self {
|
||||||
Self::X(mw, _) => [area.x(), area.y(), area.w().min(*mw), area.h()],
|
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)],
|
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|{
|
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()]
|
[area.x() + self.dx(), area.y() + self.dy(), area.w(), area.h()]
|
||||||
});
|
});
|
||||||
|
|
||||||
transform_xy_unit!(|self: Pull, area|{
|
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()]
|
[area.x().minus(self.dx()), area.y().minus(self.dy()), area.w(), area.h()]
|
||||||
});
|
});
|
||||||
|
|
||||||
transform_xy_unit!(|self: Margin, area|{
|
transform_xy_unit!(|self: Margin, area|{
|
||||||
let area = self.content().area(area);
|
let area = self.content().layout(area);
|
||||||
let dx = self.dx();
|
let dx = self.dx();
|
||||||
let dy = self.dy();
|
let dy = self.dy();
|
||||||
[area.x().minus(dx), area.y().minus(dy), area.w() + dy + dy, area.h() + dy + dy]
|
[area.x().minus(dx), area.y().minus(dy), area.w() + dy + dy, area.h() + dy + dy]
|
||||||
});
|
});
|
||||||
|
|
||||||
transform_xy_unit!(|self: Padding, area|{
|
transform_xy_unit!(|self: Padding, area|{
|
||||||
let area = self.content().area(area);
|
let area = self.content().layout(area);
|
||||||
let dx = self.dx();
|
let dx = self.dx();
|
||||||
let dy = self.dy();
|
let dy = self.dy();
|
||||||
[area.x() + dx, area.y() + dy, area.w().minus(dy + dy), area.h().minus(dy + dy), ]
|
[area.x() + dx, area.y() + dy, area.w().minus(dy + dy), area.h().minus(dy + dy), ]
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,10 @@ render!(Tui: (self: Groovebox) => {
|
||||||
PhraseSelector::play_phrase(&self.player),
|
PhraseSelector::play_phrase(&self.player),
|
||||||
PhraseSelector::next_phrase(&self.player),
|
PhraseSelector::next_phrase(&self.player),
|
||||||
)));
|
)));
|
||||||
let pool = PoolView(&self.pool);
|
"tabula rasa"
|
||||||
let with_pool = move|x|Bsp::w(Fixed::x(pool_w, Pull::y(1, Fill::y(Align::e(pool)))), x);
|
//let pool = PoolView(&self.pool);
|
||||||
with_pool(col!(transport, selector))
|
//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
|
//selector
|
||||||
//let sampler = move|x|Bsp::e(
|
//let sampler = move|x|Bsp::e(
|
||||||
//Fixed::x(sampler_w, Fill::xy(col!(
|
//Fixed::x(sampler_w, Fill::xy(col!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue