Implement {SelectView, MenuPopup}::important_area

This commit is contained in:
Alexandre Bury 2018-03-22 14:31:28 -07:00
parent 4778e4de6f
commit 5673b59c10
2 changed files with 16 additions and 0 deletions

View File

@ -4,6 +4,7 @@ use With;
use align::Align; use align::Align;
use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
use menu::{MenuItem, MenuTree}; use menu::{MenuItem, MenuTree};
use rect::Rect;
use std::cmp::min; use std::cmp::min;
use std::rc::Rc; use std::rc::Rc;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
@ -403,4 +404,12 @@ impl View for MenuPopup {
self.menu.children.len(), self.menu.children.len(),
); );
} }
fn important_area(&self, size: Vec2) -> Rect {
if self.menu.is_empty() {
return Rect::from((0, 0));
}
Rect::from_size((0, self.focus), (size.x, 1))
}
} }

View File

@ -5,6 +5,7 @@ use align::{Align, HAlign, VAlign};
use direction::Direction; use direction::Direction;
use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
use menu::MenuTree; use menu::MenuTree;
use rect::Rect;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::cell::Cell; use std::cell::Cell;
use std::cmp::min; use std::cmp::min;
@ -765,6 +766,12 @@ impl<T: 'static> View for SelectView<T> {
.set_heights(size.y, self.items.len()); .set_heights(size.y, self.items.len());
} }
} }
fn important_area(&self, size: Vec2) -> Rect {
self.selected_id()
.map(|i| Rect::from_size((0, i), (size.x, 1)))
.unwrap_or(Rect::from((0, 0)))
}
} }
struct Item<T> { struct Item<T> {