From 8f04356baa9c99ac2b018197c9e9168f5b48c030 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Fri, 23 Mar 2018 17:00:46 -0700 Subject: [PATCH] Implement ListView::important_area --- src/views/list_view.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/views/list_view.rs b/src/views/list_view.rs index ab51c76..b7785f8 100644 --- a/src/views/list_view.rs +++ b/src/views/list_view.rs @@ -3,6 +3,7 @@ use Printer; use With; use direction; use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; +use rect::Rect; use std::any::Any; use std::rc::Rc; use unicode_width::UnicodeWidthStr; @@ -494,4 +495,22 @@ impl View for ListView { 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) + } }