wip: refactor pt.29: 12 errors

This commit is contained in:
🪞👃🪞 2024-11-14 20:56:23 +01:00
parent ceead4131c
commit ab85a86b6b
27 changed files with 1890 additions and 1865 deletions

View file

@ -122,6 +122,21 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Option<W> {
self.as_ref().map(|widget|widget.render(to)).unwrap_or(Ok(()))
}
}
/// Render either of two widgets depending on predicate
pub struct Either<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>>(
pub bool,
pub A,
pub B,
);
impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Widget for Either<E, A, B> {
type Engine = E;
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
if self.0 { self.1.layout(to) } else { self.2.layout(to) }
}
fn render (&self, to: &mut E::Output) -> Usually<()> {
if self.0 { self.1.render(to) } else { self.2.render(to) }
}
}
/// A custom [Widget] defined by passing layout and render closures in place.
pub struct CustomWidget<
E: Engine,