mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-27 11:16:03 +00:00
Implement {SelectView, MenuPopup}::important_area
This commit is contained in:
parent
4778e4de6f
commit
5673b59c10
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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<T: 'static> View for SelectView<T> {
|
||||
.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> {
|
||||
|
Loading…
Reference in New Issue
Block a user