mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
sweeeeping sweep
This commit is contained in:
parent
c9b09b7dea
commit
e677d1d7d4
38 changed files with 766 additions and 691 deletions
|
|
@ -1,30 +1,10 @@
|
|||
//! Groupings of elements.
|
||||
|
||||
mod bsp; pub use self::bsp::*;
|
||||
mod split; pub use self::split::*;
|
||||
mod stack; pub use self::stack::*;
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// A function or closure that emits renderables.
|
||||
pub trait Collector<E: Engine>: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
|
||||
|
||||
/// Any function or closure that emits renderables for the given engine matches [CollectCallback].
|
||||
impl<E, F> Collector<E> for F
|
||||
where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
|
||||
|
||||
pub struct Map<E, T, I, R, F>(PhantomData<E>, I, F)
|
||||
where E: Engine, I: Iterator<Item = T>, R: Content<E>, F: Fn(T)->R;
|
||||
|
||||
pub struct Reduce<E, T, I, R, F>(PhantomData<(E, R)>, I, F)
|
||||
where E: Engine, I: Iterator<Item = T>, R: Content<E>, F: Fn(&dyn Content<E>, T)->R;
|
||||
|
||||
impl<E: Engine, T, I: Iterator<Item=T>+Send+Sync, R: Content<E>, F: Fn(&dyn Content<E>, T)->R+Send+Sync> Content<E> for Reduce<E, T, I, R, F> {
|
||||
fn render (&self, _to: &mut E::Output) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Conditional rendering, in unary and binary forms.
|
||||
pub struct Cond;
|
||||
|
||||
|
|
@ -74,3 +54,70 @@ impl<E: Engine, A: Content<E>, B: Content<E>> Content<E> for Either<E, A, B> {
|
|||
if *cond { a.render(to) } else { b.render(to) }
|
||||
}
|
||||
}
|
||||
|
||||
/// A function or closure that emits renderables.
|
||||
pub trait Collector<E: Engine>: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
|
||||
|
||||
/// Any function or closure that emits renderables for the given engine matches [CollectCallback].
|
||||
impl<E, F> Collector<E> for F
|
||||
where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
|
||||
|
||||
/*
|
||||
/// Rendering of iterable collections, one-to-one and many-to one.
|
||||
pub struct Coll;
|
||||
|
||||
impl Coll {
|
||||
pub fn map <E, T, I, R, F>(iterator: I, callback: F) -> Map<E, T, I, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync
|
||||
{
|
||||
Map(Default::default(), iterator, callback)
|
||||
}
|
||||
pub fn reduce <E, T, I, R, F>(iterator: I, callback: F) -> Reduce<E, T, I, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(R, T, usize) -> R + Send + Sync
|
||||
{
|
||||
Reduce(Default::default(), iterator, callback)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Map<'a, E, T, I, R, F>(PhantomData<E>, &'a mut I, F) where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync;
|
||||
impl<'a, E, T, I, R, F> Content<E> for Map<'a, E, T, I, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync
|
||||
{
|
||||
fn render (&self, to: &mut E::Output) {
|
||||
let mut index = 0;
|
||||
for item in self.1 {
|
||||
(self.2)(item, index).render(to);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Reduce<E, T, I, R, F>(PhantomData<(E, R)>, I, F) where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(R, T, usize) -> R + Send + Sync;
|
||||
impl<E, T, I, R, F> Content<E> for Reduce<E, T, I, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(R, T, usize) -> R + Send + Sync
|
||||
{
|
||||
fn render (&self, to: &mut E::Output) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
use crate::*;
|
||||
|
||||
/// Renders multiple things on top of each other,
|
||||
macro_rules! lay {
|
||||
($($expr:expr),*) => {{
|
||||
let layers = ();
|
||||
$(let layers = Bsp::b(layers, $expr);)*;
|
||||
layers
|
||||
}}
|
||||
}
|
||||
|
||||
/// Renders multiple things on top of each other,
|
||||
macro_rules! col {
|
||||
($($expr:expr),*) => {{
|
||||
let layers = ();
|
||||
$(let layers = Bsp::s(layers, $expr);)*;
|
||||
layers
|
||||
}}
|
||||
}
|
||||
|
||||
pub enum Bsp<E: Engine, X: Content<E>, Y: Content<E>> {
|
||||
/// X is north of Y
|
||||
N(f64, Option<X>, Option<Y>),
|
||||
/// X is south of Y
|
||||
S(f64, Option<X>, Option<Y>),
|
||||
/// X is east of Y
|
||||
E(f64, Option<X>, Option<Y>),
|
||||
/// X is west of Y
|
||||
W(f64, Option<X>, Option<Y>),
|
||||
/// X is above Y
|
||||
A(Option<X>, Option<Y>),
|
||||
/// X is below Y
|
||||
B(Option<X>, Option<Y>),
|
||||
/// Should be avoided.
|
||||
Null(PhantomData<E>),
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Bsp<E, X, Y> {
|
||||
pub fn n (p: f64, x: X, y: Y) -> Self { Self::N(p, Some(x), Some(y)) }
|
||||
pub fn s (p: f64, x: X, y: Y) -> Self { Self::S(p, Some(x), Some(y)) }
|
||||
pub fn e (p: f64, x: X, y: Y) -> Self { Self::E(p, Some(x), Some(y)) }
|
||||
pub fn w (p: f64, x: X, y: Y) -> Self { Self::W(p, Some(x), Some(y)) }
|
||||
pub fn a (x: X, y: Y) -> Self { Self::A(Some(x), Some(y)) }
|
||||
pub fn b (x: X, y: Y) -> Self { Self::B(Some(x), Some(y)) }
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Default for Bsp<E, X, Y> {
|
||||
fn default () -> Self {
|
||||
Self::Null(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Content<E> for Bsp<E, X, Y> {
|
||||
fn render (&self, to: &mut E::Output) {
|
||||
let n = E::Size::zero();
|
||||
let s = to.wh();
|
||||
match self {
|
||||
Self::Null(_) => {},
|
||||
//Self::S(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let h = s_a.h().into();
|
||||
//to.render_in(to.area().clip_h(h).into(), a);
|
||||
//to.render_in(to.area().shrink_y(h).push_y(h).into(), b);
|
||||
//},
|
||||
//Self::E(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let w = s_a.w().into();
|
||||
//to.render_in(to.area().clip_w(w).into(), a);
|
||||
//to.render_in(to.area().push_x(w).shrink_x(w).into(), b);
|
||||
//},
|
||||
//Self::W(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let w = (to.area().w() - s_a.w()).into();
|
||||
//to.render_in(to.area().push_x(w).into(), a);
|
||||
//to.render_in(to.area().shrink_x(w).into(), b);
|
||||
//},
|
||||
//Self::N(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let h = to.area().h() - s_a.h();
|
||||
//to.render_in(to.area().push_y(h).into(), a);
|
||||
//to.render_in(to.area().shrink_y(h).into(), b);
|
||||
//},
|
||||
_ => todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,3 +50,110 @@ impl Direction {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Renders multiple things on top of each other,
|
||||
#[macro_export] macro_rules! lay {
|
||||
($($expr:expr),* $(,)?) => {{
|
||||
let bsp = ();
|
||||
$(let bsp = Bsp::b(bsp, $expr);)*;
|
||||
bsp
|
||||
}}
|
||||
}
|
||||
|
||||
/// Stack southward.
|
||||
#[macro_export] macro_rules! col {
|
||||
($($expr:expr),* $(,)?) => {{
|
||||
let bsp = ();
|
||||
$(let bsp = Bsp::s(bsp, $expr);)*;
|
||||
bsp
|
||||
}};
|
||||
}
|
||||
|
||||
/// Stack northward.
|
||||
#[macro_export] macro_rules! col_up {
|
||||
($($expr:expr),* $(,)?) => {{
|
||||
let bsp = ();
|
||||
$(let bsp = Bsp::n(bsp, $expr);)*;
|
||||
bsp
|
||||
}}
|
||||
}
|
||||
|
||||
/// Stack eastward.
|
||||
#[macro_export] macro_rules! row {
|
||||
($($expr:expr),* $(,)?) => {{
|
||||
let bsp = ();
|
||||
$(let bsp = Bsp::e(bsp, $expr);)*;
|
||||
bsp
|
||||
}};
|
||||
}
|
||||
|
||||
pub enum Bsp<E: Engine, X: Content<E>, Y: Content<E>> {
|
||||
/// X is north of Y
|
||||
N(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is south of Y
|
||||
S(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is east of Y
|
||||
E(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is west of Y
|
||||
W(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is above Y
|
||||
A(Option<X>, Option<Y>),
|
||||
/// X is below Y
|
||||
B(Option<X>, Option<Y>),
|
||||
/// Should be avoided.
|
||||
Null(PhantomData<E>),
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Bsp<E, X, Y> {
|
||||
pub fn n (x: X, y: Y) -> Self { Self::N(None, Some(x), Some(y)) }
|
||||
pub fn s (x: X, y: Y) -> Self { Self::S(None, Some(x), Some(y)) }
|
||||
pub fn e (x: X, y: Y) -> Self { Self::E(None, Some(x), Some(y)) }
|
||||
pub fn w (x: X, y: Y) -> Self { Self::W(None, Some(x), Some(y)) }
|
||||
pub fn a (x: X, y: Y) -> Self { Self::A(Some(x), Some(y)) }
|
||||
pub fn b (x: X, y: Y) -> Self { Self::B(Some(x), Some(y)) }
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Default for Bsp<E, X, Y> {
|
||||
fn default () -> Self {
|
||||
Self::Null(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Content<E> for Bsp<E, X, Y> {
|
||||
fn render (&self, to: &mut E::Output) {
|
||||
let n = E::Size::zero();
|
||||
let s = to.wh();
|
||||
match self {
|
||||
Self::Null(_) => {},
|
||||
//Self::S(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let h = s_a.h().into();
|
||||
//to.render_in(to.area().clip_h(h).into(), a);
|
||||
//to.render_in(to.area().shrink_y(h).push_y(h).into(), b);
|
||||
//},
|
||||
//Self::E(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let w = s_a.w().into();
|
||||
//to.render_in(to.area().clip_w(w).into(), a);
|
||||
//to.render_in(to.area().push_x(w).shrink_x(w).into(), b);
|
||||
//},
|
||||
//Self::W(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let w = (to.area().w() - s_a.w()).into();
|
||||
//to.render_in(to.area().push_x(w).into(), a);
|
||||
//to.render_in(to.area().shrink_x(w).into(), b);
|
||||
//},
|
||||
//Self::N(p, a, b) => {
|
||||
//let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
//let _ = b.min_size(s)?.unwrap_or(n);
|
||||
//let h = to.area().h() - s_a.h();
|
||||
//to.render_in(to.area().push_y(h).into(), a);
|
||||
//to.render_in(to.area().shrink_y(h).into(), b);
|
||||
//},
|
||||
_ => todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ macro_rules! transform_xy {
|
|||
}
|
||||
impl<E: Engine, T: Content<E>> Content<E> for $Enum<E, T> {
|
||||
fn content (&self) -> Option<impl Content<E>> {
|
||||
match self {
|
||||
Self::_Unused(_) => None,
|
||||
Self::X(item) => Some(item),
|
||||
Self::Y(item) => Some(item),
|
||||
Self::XY(item) => Some(item),
|
||||
}
|
||||
Some(match self {
|
||||
Self::X(item) => item,
|
||||
Self::Y(item) => item,
|
||||
Self::XY(item) => item,
|
||||
_ => unreachable!()
|
||||
})
|
||||
}
|
||||
fn area (&$self, $to: <E as Engine>::Area) -> <E as Engine>::Area {
|
||||
$area
|
||||
|
|
@ -42,16 +42,13 @@ macro_rules! transform_xy {
|
|||
|
||||
transform_xy!(self: Fill |to|{
|
||||
let [x0, y0, wmax, hmax] = to.xywh();
|
||||
if let Some(content) = self.content() {
|
||||
let [x, y, w, h] = content.area(to).xywh();
|
||||
return match self {
|
||||
Self::X(_) => [x0, y, wmax, h],
|
||||
Self::Y(_) => [x, y0, w, hmax],
|
||||
Self::XY(_) => [x0, y0, wmax, hmax],
|
||||
_ => unreachable!()
|
||||
}.into()
|
||||
}
|
||||
return [0.into(), 0.into(), 0.into(), 0.into(),].into()
|
||||
let [x, y, w, h] = self.content().unwrap().area(to).xywh();
|
||||
return match self {
|
||||
Self::X(_) => [x0, y, wmax, h],
|
||||
Self::Y(_) => [x, y0, w, hmax],
|
||||
Self::XY(_) => [x0, y0, wmax, hmax],
|
||||
_ => unreachable!()
|
||||
}.into()
|
||||
});
|
||||
|
||||
/// Defines an enum that transforms its content parametrically
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue