1 use crate::{EventCtx, GfxCtx, Outcome, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOutput}; 2 3 pub struct Nothing {} 4 5 impl WidgetImpl for Nothing { get_dims(&self) -> ScreenDims6 fn get_dims(&self) -> ScreenDims { 7 unreachable!() 8 } 9 set_pos(&mut self, _top_left: ScreenPt)10 fn set_pos(&mut self, _top_left: ScreenPt) { 11 unreachable!() 12 } 13 event(&mut self, _: &mut EventCtx, _: &mut WidgetOutput)14 fn event(&mut self, _: &mut EventCtx, _: &mut WidgetOutput) { 15 unreachable!() 16 } draw(&self, _g: &mut GfxCtx)17 fn draw(&self, _g: &mut GfxCtx) { 18 unreachable!() 19 } 20 } 21 22 pub struct Container { 23 // false means column 24 pub is_row: bool, 25 pub members: Vec<Widget>, 26 } 27 28 impl Container { new(is_row: bool, mut members: Vec<Widget>) -> Container29 pub fn new(is_row: bool, mut members: Vec<Widget>) -> Container { 30 members.retain(|w| !w.widget.is::<Nothing>()); 31 Container { is_row, members } 32 } 33 } 34 35 impl WidgetImpl for Container { get_dims(&self) -> ScreenDims36 fn get_dims(&self) -> ScreenDims { 37 // TODO This impl isn't correct, but it works for the one use case of 38 // get_width_for_forcing. 39 let mut width: f64 = 0.0; 40 for x in &self.members { 41 width = width.max(x.get_width_for_forcing()); 42 } 43 ScreenDims::new(width, 0.0) 44 } set_pos(&mut self, _top_left: ScreenPt)45 fn set_pos(&mut self, _top_left: ScreenPt) { 46 unreachable!() 47 } 48 event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput)49 fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) { 50 for w in &mut self.members { 51 w.widget.event(ctx, output); 52 if output.outcome != Outcome::Nothing { 53 return; 54 } 55 } 56 } 57 draw(&self, g: &mut GfxCtx)58 fn draw(&self, g: &mut GfxCtx) { 59 for w in &self.members { 60 w.draw(g); 61 } 62 } 63 } 64