use crate::{EventCtx, GfxCtx, Outcome, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOutput};
pub struct Nothing {}
impl WidgetImpl for Nothing {
fn get_dims(&self) -> ScreenDims {
unreachable!()
}
fn set_pos(&mut self, _top_left: ScreenPt) {
unreachable!()
}
fn event(&mut self, _: &mut EventCtx, _: &mut WidgetOutput) {
unreachable!()
}
fn draw(&self, _g: &mut GfxCtx) {
unreachable!()
}
}
pub struct Container {
pub is_row: bool,
pub members: Vec<Widget>,
}
impl Container {
pub fn new(is_row: bool, mut members: Vec<Widget>) -> Container {
members.retain(|w| !w.widget.is::<Nothing>());
Container { is_row, members }
}
}
impl WidgetImpl for Container {
fn get_dims(&self) -> ScreenDims {
let mut width: f64 = 0.0;
for x in &self.members {
width = width.max(x.get_width_for_forcing());
}
ScreenDims::new(width, 0.0)
}
fn set_pos(&mut self, _top_left: ScreenPt) {
unreachable!()
}
fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) {
for w in &mut self.members {
if let Some(id) = ctx.focus_owned_by.as_ref() {
if w.id.as_ref() != Some(id) && !w.widget.is::<Container>() {
continue;
}
}
w.widget.event(ctx, output);
if !matches!(output.outcome, Outcome::Nothing) {
return;
}
}
}
fn draw(&self, g: &mut GfxCtx) {
for w in &self.members {
w.draw(g);
}
}
}