mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 21:56:42 +01:00
23 lines
647 B
Rust
23 lines
647 B
Rust
use crate::*;
|
|
|
|
/// Show an item only when a condition is true.
|
|
pub struct When<A>(pub bool, pub A);
|
|
|
|
impl<E: Output, A: Render<E>> Content<E> for When<A> {
|
|
fn layout (&self, to: E::Area) -> E::Area {
|
|
let Self(cond, item) = self;
|
|
let mut area = E::Area::zero();
|
|
if *cond {
|
|
let item_area = item.layout(to);
|
|
area[0] = item_area.x();
|
|
area[1] = item_area.y();
|
|
area[2] = item_area.w();
|
|
area[3] = item_area.h();
|
|
}
|
|
area.into()
|
|
}
|
|
fn render (&self, to: &mut E) {
|
|
let Self(cond, item) = self;
|
|
if *cond { item.render(to) }
|
|
}
|
|
}
|