cursive/src/view/mod.rs

98 lines
2.3 KiB
Rust
Raw Normal View History

2015-05-15 19:16:58 +00:00
//! Defines various views to use when creating the layout.
2016-07-02 03:23:58 +00:00
#[macro_use]
mod view_wrapper;
// Essentials components
mod position;
mod view_path;
// Helper bases
mod scroll;
// Views
mod box_view;
2015-05-19 02:41:35 +00:00
mod button;
mod dialog;
mod edit_view;
2015-05-22 23:28:05 +00:00
mod full_view;
2015-05-23 17:33:29 +00:00
mod id_view;
mod key_event_view;
mod linear_layout;
2016-07-02 08:01:09 +00:00
mod menu_popup;
mod shadow_view;
mod select_view;
mod sized_view;
mod stack_view;
mod text_view;
2016-07-02 03:23:58 +00:00
mod tracked_view;
use std::any::Any;
2015-05-09 19:18:25 +00:00
2016-03-15 22:37:57 +00:00
use event::{Event, EventResult};
use vec::Vec2;
use printer::Printer;
pub use self::position::{Position, Offset};
pub use self::scroll::ScrollBase;
2015-07-28 13:57:52 +00:00
pub use self::id_view::IdView;
pub use self::box_view::BoxView;
2015-05-19 02:41:35 +00:00
pub use self::button::Button;
pub use self::dialog::Dialog;
pub use self::edit_view::EditView;
2015-05-22 23:28:05 +00:00
pub use self::full_view::FullView;
pub use self::key_event_view::KeyEventView;
pub use self::linear_layout::LinearLayout;
2016-07-02 08:01:09 +00:00
pub use self::menu_popup::MenuPopup;
pub use self::view_path::ViewPath;
pub use self::select_view::SelectView;
pub use self::shadow_view::ShadowView;
pub use self::stack_view::StackView;
pub use self::text_view::TextView;
2016-07-02 03:23:58 +00:00
pub use self::tracked_view::TrackedView;
pub use self::sized_view::SizedView;
pub use self::view_wrapper::ViewWrapper;
2015-05-09 19:18:25 +00:00
2015-05-23 17:33:29 +00:00
/// Main trait defining a view behaviour.
pub trait View {
/// Called when a key was pressed. Default implementation just ignores it.
2016-03-15 22:37:57 +00:00
fn on_event(&mut self, Event) -> EventResult {
EventResult::Ignored
}
2015-05-23 17:33:29 +00:00
/// Returns the minimum size the view requires under the given restrictions.
fn get_min_size(&mut self, Vec2) -> Vec2 {
2016-03-15 22:37:57 +00:00
Vec2::new(1, 1)
}
2015-05-23 17:33:29 +00:00
/// Called once the size for this view has been decided, so it can
/// propagate the information to its children.
2016-06-25 23:36:22 +00:00
fn layout(&mut self, Vec2) {}
2015-05-23 17:33:29 +00:00
/// Draws the view with the given printer (includes bounds) and focus.
fn draw(&mut self, printer: &Printer);
2015-05-23 17:33:29 +00:00
/// Finds the view pointed to by the given path.
/// Returns None if the path doesn't lead to a view.
2016-03-15 22:37:57 +00:00
fn find(&mut self, &Selector) -> Option<&mut Any> {
None
}
2015-05-23 17:33:29 +00:00
/// This view is offered focus. Will it take it?
2016-03-15 22:37:57 +00:00
fn take_focus(&mut self) -> bool {
false
}
2015-05-23 17:33:29 +00:00
}
/// Selects a single view (if any) in the tree.
pub enum Selector<'a> {
2015-06-08 22:38:10 +00:00
/// Selects a view from its ID
2015-05-23 17:33:29 +00:00
Id(&'a str),
2015-06-08 22:38:10 +00:00
/// Selects a view from its path
2015-05-23 17:33:29 +00:00
Path(&'a ViewPath),
}