diff --git a/examples/progress.rs b/examples/progress.rs index 06d7c1e..5cfc962 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -4,7 +4,7 @@ extern crate rand; use rand::Rng; use cursive::prelude::*; -use cursive::view::Counter; +use cursive::views::Counter; use std::thread; use std::cmp::min; diff --git a/src/lib.rs b/src/lib.rs index 8222fd5..3e6e6da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,10 @@ macro_rules! new_default( pub mod prelude; pub mod event; +#[macro_use] pub mod view; + +pub mod views; pub mod vec; pub mod theme; pub mod align; @@ -104,7 +107,6 @@ use std::path::Path; use vec::Vec2; use view::View; -use view::{Selector, StackView}; use event::{Callback, Event, EventResult}; @@ -120,9 +122,9 @@ pub type ScreenId = usize; /// It uses a list of screen, with one screen active at a time. pub struct Cursive { theme: theme::Theme, - screens: Vec, + screens: Vec, global_callbacks: HashMap, - menubar: view::Menubar, + menubar: views::Menubar, active_screen: ScreenId, @@ -153,14 +155,14 @@ impl Cursive { theme: theme, screens: Vec::new(), global_callbacks: HashMap::new(), - menubar: view::Menubar::new(), + menubar: views::Menubar::new(), active_screen: 0, running: true, cb_source: rx, cb_sink: tx, }; - res.screens.push(StackView::new()); + res.screens.push(views::StackView::new()); res } @@ -237,7 +239,7 @@ impl Cursive { /// siv.add_global_callback(Key::Esc, |s| s.select_menubar()); /// # } /// ``` - pub fn menubar(&mut self) -> &mut view::Menubar { + pub fn menubar(&mut self) -> &mut views::Menubar { &mut self.menubar } @@ -273,13 +275,13 @@ impl Cursive { } /// Returns a reference to the currently active screen. - pub fn screen(&self) -> &StackView { + pub fn screen(&self) -> &views::StackView { let id = self.active_screen; &self.screens[id] } /// Returns a mutable reference to the currently active screen. - pub fn screen_mut(&mut self) -> &mut StackView { + pub fn screen_mut(&mut self) -> &mut views::StackView { let id = self.active_screen; self.screens.get_mut(id).unwrap() } @@ -287,7 +289,7 @@ impl Cursive { /// Adds a new screen, and returns its ID. pub fn add_screen(&mut self) -> ScreenId { let res = self.screens.len(); - self.screens.push(StackView::new()); + self.screens.push(views::StackView::new()); res } @@ -309,7 +311,7 @@ impl Cursive { self.active_screen = screen_id; } - fn find_any(&mut self, selector: &Selector) -> Option<&mut Any> { + fn find_any(&mut self, selector: &view::Selector) -> Option<&mut Any> { // Internal find method that returns a Any object. self.screen_mut().find(selector) } @@ -336,14 +338,14 @@ impl Cursive { /// }); /// # } /// ``` - pub fn find(&mut self, sel: &Selector) -> Option<&mut V> { + pub fn find(&mut self, sel: &view::Selector) -> Option<&mut V> { match self.find_any(sel) { None => None, Some(b) => b.downcast_mut::(), } } - /// Convenient method to use `find` with a `Selector::Id`. + /// Convenient method to use `find` with a `view::Selector::Id`. /// /// # Examples /// @@ -363,7 +365,7 @@ impl Cursive { /// # } /// ``` pub fn find_id(&mut self, id: &str) -> Option<&mut V> { - self.find(&Selector::Id(id)) + self.find(&view::Selector::Id(id)) } /// Adds a global callback. diff --git a/src/prelude.rs b/src/prelude.rs index 0d6ef49..cb044a5 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -8,8 +8,9 @@ pub use {Cursive, Printer, With}; pub use event::{Event, Key}; -pub use view::{BoxView, Button, Checkbox, Dialog, EditView, FullView, IdView, - Identifiable, KeyEventView, LinearLayout, ListView, Panel, - ProgressBar, SelectView, Selector, TextView, View}; +pub use view::{Identifiable, Selector, View}; +pub use views::{BoxView, Button, Checkbox, Dialog, EditView, FullView, + IdView, KeyEventView, LinearLayout, ListView, Panel, + ProgressBar, SelectView, TextView}; pub use vec::Vec2; pub use menu::MenuTree; diff --git a/src/view/mod.rs b/src/view/mod.rs index 694f02a..9efb516 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -1,4 +1,4 @@ -//! Defines various views to use when creating the layout. +//! Define the base elements required to build views. //! //! Views are the main building blocks of your UI. //! @@ -46,26 +46,6 @@ mod view_path; mod scroll; // Views -mod box_view; -mod button; -mod checkbox; -mod dialog; -mod edit_view; -mod full_view; -mod id_view; -mod key_event_view; -mod linear_layout; -mod list_view; -mod menubar; -mod menu_popup; -mod panel; -mod progress_bar; -mod shadow_view; -mod select_view; -mod sized_view; -mod stack_view; -mod text_view; -mod tracked_view; use std::any::Any; @@ -80,27 +60,7 @@ pub use self::position::{Offset, Position}; pub use self::scroll::ScrollBase; -pub use self::id_view::{IdView, Identifiable}; -pub use self::box_view::BoxView; -pub use self::button::Button; -pub use self::checkbox::Checkbox; -pub use self::dialog::Dialog; -pub use self::edit_view::EditView; -pub use self::full_view::FullView; -pub use self::key_event_view::KeyEventView; -pub use self::linear_layout::LinearLayout; -pub use self::list_view::ListView; -pub use self::menubar::Menubar; -pub use self::menu_popup::MenuPopup; pub use self::view_path::ViewPath; -pub use self::panel::Panel; -pub use self::progress_bar::{Counter, ProgressBar}; -pub use self::select_view::SelectView; -pub use self::shadow_view::ShadowView; -pub use self::sized_view::SizedView; -pub use self::stack_view::StackView; -pub use self::text_view::TextView; -pub use self::tracked_view::TrackedView; pub use self::view_wrapper::ViewWrapper; @@ -218,7 +178,7 @@ impl SizeCache { /// /// * `size` must fit inside `req`. /// * for each dimension, `constrained = (size == req)` - fn build(size: Vec2, req: Vec2) -> XY { + pub fn build(size: Vec2, req: Vec2) -> XY { XY::new(SizeCache::new(size.x, size.x >= req.x), SizeCache::new(size.y, size.y >= req.y)) } @@ -232,3 +192,13 @@ pub enum Selector<'a> { /// Selects a view from its path. Path(&'a ViewPath), } + +/// Makes a view wrappable in an `IdView`. +pub trait Identifiable: View + Sized { + /// Wraps this view into an IdView with the given id. + fn with_id(self, id: &str) -> ::views::IdView { + ::views::IdView::new(id, self) + } +} + +impl Identifiable for T {} diff --git a/src/view/box_view.rs b/src/views/box_view.rs similarity index 97% rename from src/view/box_view.rs rename to src/views/box_view.rs index 974ac19..71c706d 100644 --- a/src/view/box_view.rs +++ b/src/views/box_view.rs @@ -2,7 +2,7 @@ use std::cmp; use XY; use vec::Vec2; -use super::{View, ViewWrapper}; +use view::{View, ViewWrapper}; /// Wrapper around another view, with a fixed size. /// @@ -17,7 +17,7 @@ use super::{View, ViewWrapper}; /// # Examples /// /// ``` -/// # use cursive::view::{BoxView,TextView}; +/// # use cursive::views::{BoxView,TextView}; /// // Creates a 20x4 BoxView with a TextView content. /// let view = BoxView::fixed_size((20,4), TextView::new("Hello!")); /// ``` diff --git a/src/view/button.rs b/src/views/button.rs similarity index 100% rename from src/view/button.rs rename to src/views/button.rs diff --git a/src/view/checkbox.rs b/src/views/checkbox.rs similarity index 100% rename from src/view/checkbox.rs rename to src/views/checkbox.rs diff --git a/src/view/dialog.rs b/src/views/dialog.rs similarity index 99% rename from src/view/dialog.rs rename to src/views/dialog.rs index d86a778..4a4f903 100644 --- a/src/view/dialog.rs +++ b/src/views/dialog.rs @@ -7,8 +7,8 @@ use direction::Direction; use align::*; use event::*; use theme::ColorStyle; -use view::{DummyView, Selector, TextView, View}; -use view::{Button, SizedView}; +use view::{DummyView, Selector, View}; +use views::{Button, SizedView, TextView}; use vec::{Vec2, Vec4}; use Printer; @@ -25,7 +25,7 @@ enum Focus { /// # Examples /// /// ``` -/// # use cursive::view::{Dialog,TextView}; +/// # use cursive::views::{Dialog,TextView}; /// let dialog = Dialog::new(TextView::new("Hello!")) /// .button("Ok", |s| s.quit()); /// ``` diff --git a/src/view/edit_view.rs b/src/views/edit_view.rs similarity index 100% rename from src/view/edit_view.rs rename to src/views/edit_view.rs diff --git a/src/view/full_view.rs b/src/views/full_view.rs similarity index 100% rename from src/view/full_view.rs rename to src/views/full_view.rs diff --git a/src/view/id_view.rs b/src/views/id_view.rs similarity index 73% rename from src/view/id_view.rs rename to src/views/id_view.rs index 8e64740..102107f 100644 --- a/src/view/id_view.rs +++ b/src/views/id_view.rs @@ -28,13 +28,3 @@ impl ViewWrapper for IdView { } } } - -/// Makes a view wrappable in an `IdView`. -pub trait Identifiable: View + Sized { - /// Wraps this view into an IdView with the given id. - fn with_id(self, id: &str) -> IdView { - IdView::new(id, self) - } -} - -impl Identifiable for T {} diff --git a/src/view/key_event_view.rs b/src/views/key_event_view.rs similarity index 98% rename from src/view/key_event_view.rs rename to src/views/key_event_view.rs index 650acc0..8d08ed7 100644 --- a/src/view/key_event_view.rs +++ b/src/views/key_event_view.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use Cursive; use event::{Callback, Event, EventResult}; -use super::{View, ViewWrapper}; +use view::{View, ViewWrapper}; /// A simple wrapper view that catches some ignored event from its child. /// diff --git a/src/view/linear_layout.rs b/src/views/linear_layout.rs similarity index 100% rename from src/view/linear_layout.rs rename to src/views/linear_layout.rs diff --git a/src/view/list_view.rs b/src/views/list_view.rs similarity index 99% rename from src/view/list_view.rs rename to src/views/list_view.rs index dcda291..cf53921 100644 --- a/src/view/list_view.rs +++ b/src/views/list_view.rs @@ -4,7 +4,7 @@ use vec::Vec2; use view::View; use view::Selector; use direction; -use view::scroll::ScrollBase; +use view::ScrollBase; use event::{Event, EventResult, Key}; use std::any::Any; diff --git a/src/view/menu_popup.rs b/src/views/menu_popup.rs similarity index 99% rename from src/view/menu_popup.rs rename to src/views/menu_popup.rs index 5e8ab94..edb9fc5 100644 --- a/src/view/menu_popup.rs +++ b/src/views/menu_popup.rs @@ -7,10 +7,8 @@ use Cursive; use With; use menu::{MenuItem, MenuTree}; use Printer; -use view::View; -use view::Position; -use view::KeyEventView; -use view::scroll::ScrollBase; +use view::{View, Position, ScrollBase}; +use views::KeyEventView; use align::Align; use vec::Vec2; use event::{Callback, Event, EventResult, Key}; diff --git a/src/view/menubar.rs b/src/views/menubar.rs similarity index 98% rename from src/view/menubar.rs rename to src/views/menubar.rs index 6207389..4d7f862 100644 --- a/src/view/menubar.rs +++ b/src/views/menubar.rs @@ -1,15 +1,12 @@ use Cursive; -use view::View; - +use view::{View, Position}; use vec::Vec2; use direction; use menu::MenuTree; use backend::Backend; -use view::MenuPopup; -use view::KeyEventView; +use views::{MenuPopup, KeyEventView}; use theme::ColorStyle; use Printer; -use view::Position; use event::*; use std::rc::Rc; diff --git a/src/views/mod.rs b/src/views/mod.rs new file mode 100644 index 0000000..f2dad61 --- /dev/null +++ b/src/views/mod.rs @@ -0,0 +1,43 @@ +//! Defines various views to use when creating the layout. + +mod box_view; +mod button; +mod checkbox; +mod dialog; +mod edit_view; +mod full_view; +mod id_view; +mod key_event_view; +mod linear_layout; +mod list_view; +mod menubar; +mod menu_popup; +mod panel; +mod progress_bar; +mod shadow_view; +mod select_view; +mod sized_view; +mod stack_view; +mod text_view; +mod tracked_view; + +pub use self::id_view::{IdView}; +pub use self::box_view::BoxView; +pub use self::button::Button; +pub use self::checkbox::Checkbox; +pub use self::dialog::Dialog; +pub use self::edit_view::EditView; +pub use self::full_view::FullView; +pub use self::key_event_view::KeyEventView; +pub use self::linear_layout::LinearLayout; +pub use self::list_view::ListView; +pub use self::menubar::Menubar; +pub use self::menu_popup::MenuPopup; +pub use self::panel::Panel; +pub use self::progress_bar::{Counter, ProgressBar}; +pub use self::select_view::SelectView; +pub use self::shadow_view::ShadowView; +pub use self::sized_view::SizedView; +pub use self::stack_view::StackView; +pub use self::text_view::TextView; +pub use self::tracked_view::TrackedView; diff --git a/src/view/panel.rs b/src/views/panel.rs similarity index 100% rename from src/view/panel.rs rename to src/views/panel.rs diff --git a/src/view/progress_bar.rs b/src/views/progress_bar.rs similarity index 100% rename from src/view/progress_bar.rs rename to src/views/progress_bar.rs diff --git a/src/view/select_view.rs b/src/views/select_view.rs similarity index 99% rename from src/view/select_view.rs rename to src/views/select_view.rs index 1cbb8b0..6911bb0 100644 --- a/src/view/select_view.rs +++ b/src/views/select_view.rs @@ -3,14 +3,12 @@ use std::rc::Rc; use std::cell::Cell; use Cursive; -use menu::MenuTree; -use view::MenuPopup; use With; +use menu::MenuTree; use direction::Direction; -use view::position::Position; -use view::{IdView, View}; +use view::{Position, ScrollBase, View}; +use views::{IdView, MenuPopup}; use align::{Align, HAlign, VAlign}; -use view::scroll::ScrollBase; use event::{Callback, Event, EventResult, Key}; use theme::ColorStyle; use vec::Vec2; diff --git a/src/view/shadow_view.rs b/src/views/shadow_view.rs similarity index 100% rename from src/view/shadow_view.rs rename to src/views/shadow_view.rs diff --git a/src/view/sized_view.rs b/src/views/sized_view.rs similarity index 100% rename from src/view/sized_view.rs rename to src/views/sized_view.rs diff --git a/src/view/stack_view.rs b/src/views/stack_view.rs similarity index 98% rename from src/view/stack_view.rs rename to src/views/stack_view.rs index 8e19da4..593e34c 100644 --- a/src/view/stack_view.rs +++ b/src/views/stack_view.rs @@ -3,7 +3,8 @@ use std::any::Any; use direction::Direction; use backend::Backend; use vec::Vec2; -use view::{Offset, Position, Selector, ShadowView, View}; +use view::{Offset, Position, Selector, View}; +use views::ShadowView; use event::{Event, EventResult}; use Printer; use theme::ColorStyle; diff --git a/src/view/text_view.rs b/src/views/text_view.rs similarity index 99% rename from src/view/text_view.rs rename to src/views/text_view.rs index c437da6..01c6a2d 100644 --- a/src/view/text_view.rs +++ b/src/views/text_view.rs @@ -2,12 +2,11 @@ use XY; use With; use direction::Direction; use vec::Vec2; -use view::View; -use view::SizeCache; +use view::{View, SizeCache}; use Printer; use align::*; use event::*; -use super::scroll::ScrollBase; +use view::ScrollBase; use utils::head_bytes; diff --git a/src/view/tracked_view.rs b/src/views/tracked_view.rs similarity index 95% rename from src/view/tracked_view.rs rename to src/views/tracked_view.rs index 966a0cb..4d171be 100644 --- a/src/view/tracked_view.rs +++ b/src/views/tracked_view.rs @@ -1,6 +1,7 @@ use std::cell::Cell; -use view::{IdView, View, ViewWrapper}; +use view::{View, ViewWrapper}; +use views::IdView; use Printer; use vec::Vec2;