dsl, output, tui: add tests, examples, root dispatchers

This commit is contained in:
🪞👃🪞 2025-09-08 18:44:42 +03:00
parent 8dfe20a58c
commit ca862b9802
16 changed files with 637 additions and 377 deletions

View file

@ -1,15 +1,15 @@
use crate::*;
/// Show an item only when a condition is true.
pub struct When<A>(pub bool, pub A);
impl<A> When<A> {
pub struct When<O, T>(bool, T, PhantomData<O>);
impl<O, T> When<O, T> {
/// Create a binary condition.
pub const fn new (c: bool, a: A) -> Self { Self(c, a) }
pub const fn new (c: bool, a: T) -> Self { Self(c, a, PhantomData) }
}
impl<E: Out, A: Layout<E>> Layout<E> for When<A> {
fn layout (&self, to: E::Area) -> E::Area {
let Self(cond, item) = self;
let mut area = E::Area::zero();
impl<O: Out, T: Layout<O>> Layout<O> for When<O, T> {
fn layout (&self, to: O::Area) -> O::Area {
let Self(cond, item, ..) = self;
let mut area = O::Area::zero();
if *cond {
let item_area = item.layout(to);
area[0] = item_area.x();
@ -20,9 +20,9 @@ impl<E: Out, A: Layout<E>> Layout<E> for When<A> {
area.into()
}
}
impl<E: Out, A: Draw<E>> Draw<E> for When<A> {
fn draw (&self, to: &mut E) {
let Self(cond, item) = self;
impl<O: Out, T: Draw<O>> Draw<O> for When<O, T> {
fn draw (&self, to: &mut O) {
let Self(cond, item, ..) = self;
if *cond { item.draw(to) }
}
}