mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-10 03:10:41 +00:00
Implement LinearLayout::important_area
This commit is contained in:
parent
bd3ea469e9
commit
5c3c750033
11
src/rect.rs
11
src/rect.rs
@ -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.
|
||||
///
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user