check pass, test pass.. but does it run?

This commit is contained in:
🪞👃🪞 2024-12-31 16:39:33 +01:00
parent 1de163d0d3
commit 9f7b23a252
10 changed files with 65 additions and 48 deletions

View file

@ -1,28 +1,47 @@
//! Groupings of elements.
mod split; pub use self::split::*;
mod stack; pub use self::stack::*;
//mod stack; pub use self::stack::*;
use crate::*;
use std::sync::RwLock;
/// Conditional rendering, in unary and binary forms.
pub struct Cond;
impl<E: Engine> Layout<E> for E {}
impl Cond {
pub trait Layout<E: Engine> {
/// Content `item` when `cond` is true.
pub fn when <E: Engine, A: Content<E>> (cond: bool, item: A) -> When<E, A> {
fn when <A: Content<E>> (cond: bool, item: A) -> When<E, A> {
When(cond, item, Default::default())
}
/// Content `item` if `cond` is true, otherwise render `other`.
pub fn either <E: Engine, A: Content<E>, B: Content<E>> (cond: bool, a: A, b: B) -> Either<E, A, B> {
fn either <A: Content<E>, B: Content<E>> (cond: bool, a: A, b: B)
-> Either<E, A, B>
{
Either(cond, a, b, Default::default())
}
pub fn opt <E: Engine, A, F: Fn(A)->R, R: Content<E>> (option: Option<A>, cb: F) -> Opt<E, A, F, R> {
/// Maps an [Option<T>] through a callback `F`
fn opt <A, F: Fn(A)->R, R: Content<E>> (option: Option<A>, cb: F)
-> Opt<E, A, F, R>
{
Opt(option, cb, Default::default())
}
fn map <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(), RwLock::new(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 Opt<E: Engine, A, F: Fn(A)->R, R: Content<E>>(Option<A>, F, PhantomData<E>);
@ -63,33 +82,31 @@ impl<E: Engine, A: Content<E>, B: Content<E>> Content<E> for Either<E, A, B> {
}
}
pub trait Render<E: Engine> {
fn area (&self, to: E::Area) -> E::Area;
fn render (&self, to: &mut E::Output);
}
impl<E: Engine, C: Content<E>> Render<E> for C {
fn area (&self, to: E::Area) -> E::Area {
Content::area(self, to)
}
fn render (&self, to: &mut E::Output) {
Content::render(self, to)
}
}
/// A function or closure that emits renderables.
pub trait Collector<E: Engine>: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
pub trait Collector<E: Engine>: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<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>)) {}
where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<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(), RwLock::new(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<E, T, I, R, F>(PhantomData<E>, RwLock<I>, F) where

View file

@ -66,11 +66,11 @@ impl<E: Engine> Measure<E> {
}
}
/// A scrollable area.
pub struct Scroll<E, F>(pub F, pub Direction, pub u64, PhantomData<E>)
where
E: Engine,
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)->Usually<()>)->Usually<()>;
///// A scrollable area.
//pub struct Scroll<E, F>(pub F, pub Direction, pub u64, PhantomData<E>)
//where
//E: Engine,
//F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)->Usually<()>)->Usually<()>;
//pub trait ContentDebug<E: Engine> {
//fn debug <W: Content<E>> (other: W) -> DebugOverlay<E, W> {

View file

@ -42,7 +42,7 @@ macro_rules! transform_xy {
transform_xy!(self: Fill |to|{
let [x0, y0, wmax, hmax] = to.xywh();
let [x, y, w, h] = self.content().area(to).xywh();
let [x, y, w, h] = Content::area(&self.content(), to).xywh();
return match self {
Self::X(_) => [x0, y, wmax, h],
Self::Y(_) => [x, y0, w, hmax],
@ -174,10 +174,10 @@ fn align<E: Engine, T: Content<E>, N: Coordinate, R: Area<N> + From<[N;4]>> (ali
impl<E: Engine, T: Content<E>> Content<E> for Align<E, T> {
fn render (&self, to: &mut E::Output) {
let outer_area = to.area();
let content = self.content();
let inner_area = content.area(outer_area);
if let Some(aligned) = align(&self, outer_area.into(), inner_area.into()) {
let outer = to.area();
let content = self.content();
let inner = Content::area(&content, outer);
if let Some(aligned) = align(&self, outer.into(), inner.into()) {
to.place(aligned, &content)
}
}