2015-05-15 19:16:58 +00:00
|
|
|
//! Defines various views to use when creating the layout.
|
|
|
|
|
2015-05-16 00:56:38 +00:00
|
|
|
mod box_view;
|
|
|
|
mod stack_view;
|
|
|
|
mod text_view;
|
|
|
|
mod key_event_view;
|
|
|
|
mod view_path;
|
2015-05-16 21:02:15 +00:00
|
|
|
mod dialog;
|
2015-05-16 00:56:38 +00:00
|
|
|
|
|
|
|
use std::any::Any;
|
2015-05-09 19:18:25 +00:00
|
|
|
|
2015-05-16 00:56:38 +00:00
|
|
|
pub use self::view_path::ViewPath;
|
|
|
|
pub use self::key_event_view::KeyEventView;
|
|
|
|
pub use self::box_view::BoxView;
|
|
|
|
pub use self::stack_view::StackView;
|
|
|
|
pub use self::text_view::TextView;
|
2015-05-16 21:02:15 +00:00
|
|
|
pub use self::dialog::Dialog;
|
2015-05-09 19:18:25 +00:00
|
|
|
|
2015-05-16 00:56:38 +00:00
|
|
|
use event::EventResult;
|
2015-05-18 18:51:30 +00:00
|
|
|
use vec::Vec2;
|
2015-05-15 18:58:47 +00:00
|
|
|
use printer::Printer;
|
2015-05-09 19:18:25 +00:00
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Describe constraints on a view layout in one dimension.
|
2015-05-15 01:38:58 +00:00
|
|
|
#[derive(PartialEq,Clone,Copy)]
|
2015-05-15 00:41:17 +00:00
|
|
|
pub enum DimensionRequest {
|
|
|
|
/// The view must use exactly the attached size.
|
|
|
|
Fixed(u32),
|
|
|
|
/// The view is free to choose its size if it stays under the limit.
|
|
|
|
AtMost(u32),
|
|
|
|
/// No clear restriction apply.
|
|
|
|
Unknown,
|
2015-05-09 19:18:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Describes constraints on a view layout.
|
2015-05-15 01:38:58 +00:00
|
|
|
#[derive(PartialEq,Clone,Copy)]
|
2015-05-15 00:41:17 +00:00
|
|
|
pub struct SizeRequest {
|
|
|
|
/// Restriction on the view width
|
|
|
|
pub w: DimensionRequest,
|
|
|
|
/// Restriction on the view height
|
|
|
|
pub h: DimensionRequest,
|
2015-05-09 19:18:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Main trait defining a view behaviour.
|
|
|
|
pub trait View {
|
|
|
|
/// Called when a key was pressed. Default implementation just ignores it.
|
|
|
|
fn on_key_event(&mut self, i32) -> EventResult { EventResult::Ignored }
|
2015-05-09 19:18:25 +00:00
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Returns the minimum size the view requires under the given restrictions.
|
2015-05-15 18:58:47 +00:00
|
|
|
fn get_min_size(&self, SizeRequest) -> Vec2 { Vec2::new(1,1) }
|
2015-05-09 19:18:25 +00:00
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Called once the size for this view has been decided, so it can
|
|
|
|
/// propagate the information to its children.
|
2015-05-15 18:58:47 +00:00
|
|
|
fn layout(&mut self, Vec2) { }
|
2015-05-09 19:18:25 +00:00
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Draws the view within the given bounds.
|
2015-05-15 18:58:47 +00:00
|
|
|
fn draw(&self, &Printer);
|
2015-05-16 00:56:38 +00:00
|
|
|
|
|
|
|
/// Finds the view pointed to by the given path.
|
|
|
|
/// Returns None if the path doesn't lead to a view.
|
|
|
|
fn find(&mut self, &ViewPath) -> Option<&mut Any> { None }
|
2015-05-09 19:18:25 +00:00
|
|
|
}
|
2015-05-16 00:56:38 +00:00
|
|
|
|