diff --git a/src/widgets/widget.rs b/src/widgets/widget.rs index 69341cb..2cd0f78 100644 --- a/src/widgets/widget.rs +++ b/src/widgets/widget.rs @@ -40,7 +40,7 @@ impl Geometry { x, y, width: max(self.width + self.x, other.width + other.x) - x, - height: max(self.height + self.y, other.height + other.height) - y, + height: max(self.height + self.y, other.height + other.y) - y, } } @@ -64,3 +64,30 @@ pub trait Widget { fn draw(&mut self, fonts: &mut FontMap, view: &mut BufferView) -> Geometry; fn event(&mut self, _event: &Event) {} } + +#[cfg(test)] +mod tests { + use super::Geometry; + + #[test] + fn expand_is_bounding_box() { + let a = Geometry { + x: 10, + y: 20, + width: 5, + height: 5, + }; + let b = Geometry { + x: 0, + y: 100, + width: 2, + height: 2, + }; + let e = a.expand(b); + assert_eq!((e.x, e.y), (0, 20)); + assert_eq!(e.x + e.width, 15); + assert_eq!(e.y + e.height, 102); + let e2 = b.expand(a); + assert_eq!((e2.x, e2.y, e2.width, e2.height), (e.x, e.y, e.width, e.height)); + } +}