Implement LinearLayout::important_area

This commit is contained in:
Alexandre Bury 2018-03-22 11:02:46 -07:00
parent bd3ea469e9
commit 5c3c750033
2 changed files with 22 additions and 0 deletions

View File

@ -1,4 +1,5 @@
//! Rectangles on the 2D character grid.
use std::ops::Add;
use vec::Vec2;
@ -21,6 +22,16 @@ where
}
}
impl <T> Add<T> for Rect
where T: Into<Vec2> {
type Output = Rect;
fn add(mut self, rhs: T) -> Self {
self.offset(rhs);
self
}
}
impl Rect {
/// Creates a new `Rect` with the given position and size.
///

View File

@ -3,6 +3,7 @@ use With;
use XY;
use direction;
use event::{Event, EventResult, Key};
use rect::Rect;
use std::any::Any;
use std::cmp::min;
use std::ops::Deref;
@ -574,4 +575,14 @@ impl View for LinearLayout {
Err(())
}
fn important_area(&self, _: Vec2) -> Rect {
let mut iterator = ChildIterator::new(self.children.iter(), self.orientation, usize::max_value());
let item = iterator.nth(self.focus).unwrap();
let rect = item.child.view.important_area(item.child.size);
let offset = self.orientation.make_vec(item.offset, 0);
rect + offset
}
}