Implement ListView::important_area

This commit is contained in:
Alexandre Bury 2018-03-23 17:00:46 -07:00
parent e81307a77c
commit 8f04356baa

View File

@ -3,6 +3,7 @@ use Printer;
use With; use With;
use direction; use direction;
use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
use rect::Rect;
use std::any::Any; use std::any::Any;
use std::rc::Rc; use std::rc::Rc;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
@ -494,4 +495,22 @@ impl View for ListView {
Err(()) Err(())
} }
} }
fn important_area(&self, size: Vec2) -> Rect {
if self.children.is_empty() {
return Rect::from((0, 0));
}
let labels_width = self.labels_width();
let area = match self.children[self.focus] {
ListChild::Row(_, ref view) => {
let available = Vec2::new(size.x - labels_width - 1, 1);
view.important_area(available) + (labels_width, 0)
}
ListChild::Delimiter => Rect::from_size((0, 0), (size.x, 1)),
};
area + (0, self.focus)
}
} }