From 5673b59c1095a8591ebfbb7a3f3a400e67fdd5b4 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 22 Mar 2018 14:31:28 -0700 Subject: [PATCH] Implement {SelectView, MenuPopup}::important_area --- src/views/menu_popup.rs | 9 +++++++++ src/views/select_view.rs | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/views/menu_popup.rs b/src/views/menu_popup.rs index 75b79f7..4d871da 100644 --- a/src/views/menu_popup.rs +++ b/src/views/menu_popup.rs @@ -4,6 +4,7 @@ use With; use align::Align; use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; use menu::{MenuItem, MenuTree}; +use rect::Rect; use std::cmp::min; use std::rc::Rc; use unicode_width::UnicodeWidthStr; @@ -403,4 +404,12 @@ impl View for MenuPopup { 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)) + } } diff --git a/src/views/select_view.rs b/src/views/select_view.rs index de140e7..984ff23 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -5,6 +5,7 @@ use align::{Align, HAlign, VAlign}; use direction::Direction; use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; use menu::MenuTree; +use rect::Rect; use std::borrow::Borrow; use std::cell::Cell; use std::cmp::min; @@ -765,6 +766,12 @@ impl View for SelectView { .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 {