#[macro_use]
mod view_wrapper;
mod position;
mod size_cache;
mod size_constraint;
mod view_path;
mod scroll;
mod identifiable;
mod boxable;
use Printer;
use direction::Direction;
use event::{Event, EventResult};
pub use self::boxable::Boxable;
pub use self::identifiable::Identifiable;
pub use self::position::{Offset, Position};
pub use self::scroll::ScrollBase;
pub use self::size_cache::SizeCache;
pub use self::size_constraint::SizeConstraint;
pub use self::view_path::ViewPath;
pub use self::view_wrapper::ViewWrapper;
use std::any::Any;
use vec::Vec2;
pub trait View {
fn on_event(&mut self, Event) -> EventResult {
EventResult::Ignored
}
fn get_min_size(&mut self, constraint: Vec2) -> Vec2 {
let _ = constraint;
Vec2::new(1, 1)
}
fn needs_relayout(&self) -> bool {
true
}
fn layout(&mut self, Vec2) {}
fn draw(&self, printer: &Printer);
fn find_any(&mut self, &Selector) -> Option<&mut Any> {
None
}
fn take_focus(&mut self, source: Direction) -> bool {
let _ = source;
false
}
}
pub trait Finder {
fn find<V: View + Any>(&mut self, sel: &Selector) -> Option<&mut V>;
fn find_id<V: View + Any>(&mut self, id: &str) -> Option<&mut V> {
self.find(&Selector::Id(id))
}
}
impl<T: View> Finder for T {
fn find<V: View + Any>(&mut self, sel: &Selector) -> Option<&mut V> {
self.find_any(sel).and_then(|b| b.downcast_mut::<V>())
}
}
pub enum Selector<'a> {
Id(&'a str),
Path(&'a ViewPath),
}