mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-12 20:23:35 +00:00
Implement Menubar::important_area
This commit is contained in:
parent
5673b59c10
commit
6729453118
@ -3,6 +3,7 @@ use Printer;
|
||||
use direction;
|
||||
use event::*;
|
||||
use menu::{MenuItem, MenuTree};
|
||||
use rect::Rect;
|
||||
use std::rc::Rc;
|
||||
use theme::ColorStyle;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
@ -383,4 +384,21 @@ impl View for Menubar {
|
||||
|
||||
Vec2::new(width, 1)
|
||||
}
|
||||
|
||||
fn important_area(&self, _: Vec2) -> Rect {
|
||||
if self.root.is_empty() {
|
||||
return Rect::from((0, 0));
|
||||
}
|
||||
|
||||
// X position is 1 (margin before the first item) + sum of widths
|
||||
// And each item has a 2 cells padding.
|
||||
let x = 1 + self.root.children[..self.focus]
|
||||
.iter()
|
||||
.map(|child| child.label().width() + 2)
|
||||
.sum::<usize>();
|
||||
|
||||
let width = self.root.children[self.focus].label().width();
|
||||
|
||||
Rect::from_size((x, 0), (width, 1))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user