Add View::important_area

In preparation for ScrollView
This commit is contained in:
Alexandre Bury 2018-03-16 18:07:01 -07:00
parent e23a5cd3a2
commit bd3ea469e9

View File

@ -1,6 +1,7 @@
use Printer;
use direction::Direction;
use event::{Event, EventResult};
use rect::Rect;
use std::any::Any;
use vec::Vec2;
use view::{AnyView, Selector};
@ -9,7 +10,6 @@ use view::{AnyView, Selector};
///
/// This is what you should implement to define a custom View.
pub trait View: Any + AnyView {
/// Draws the view with the given printer (includes bounds) and focus.
///
/// This is the only *required* method to implement.
@ -63,7 +63,6 @@ pub trait View: Any + AnyView {
EventResult::Ignored
}
/// Runs a closure on the view identified by the given selector.
///
/// See [`Finder::call_on`] for a nicer interface, implemented for all
@ -97,4 +96,16 @@ pub trait View: Any + AnyView {
let _ = source;
false
}
/// What part of the view is important and should be visible?
///
/// When only part of this view can be visible, this helps
/// determine which part.
///
/// It is given the view size (same size given to `layout`).
///
/// Default implementation return the entire view.
fn important_area(&self, view_size: Vec2) -> Rect {
Rect::from_corners((0, 0), view_size)
}
}