mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-22 02:59:02 +01:00
dsl, output, tui: add tests, examples, root dispatchers
This commit is contained in:
parent
8dfe20a58c
commit
ca862b9802
16 changed files with 637 additions and 377 deletions
|
|
@ -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) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue