Move views to new views module

This commit is contained in:
Alexandre Bury 2016-07-28 16:36:01 -07:00
parent 51a1a19f92
commit f87d0e7c5b
25 changed files with 95 additions and 95 deletions

View File

@ -4,7 +4,7 @@ extern crate rand;
use rand::Rng; use rand::Rng;
use cursive::prelude::*; use cursive::prelude::*;
use cursive::view::Counter; use cursive::views::Counter;
use std::thread; use std::thread;
use std::cmp::min; use std::cmp::min;

View File

@ -73,7 +73,10 @@ macro_rules! new_default(
pub mod prelude; pub mod prelude;
pub mod event; pub mod event;
#[macro_use]
pub mod view; pub mod view;
pub mod views;
pub mod vec; pub mod vec;
pub mod theme; pub mod theme;
pub mod align; pub mod align;
@ -104,7 +107,6 @@ use std::path::Path;
use vec::Vec2; use vec::Vec2;
use view::View; use view::View;
use view::{Selector, StackView};
use event::{Callback, Event, EventResult}; 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. /// It uses a list of screen, with one screen active at a time.
pub struct Cursive { pub struct Cursive {
theme: theme::Theme, theme: theme::Theme,
screens: Vec<StackView>, screens: Vec<views::StackView>,
global_callbacks: HashMap<Event, Callback>, global_callbacks: HashMap<Event, Callback>,
menubar: view::Menubar, menubar: views::Menubar,
active_screen: ScreenId, active_screen: ScreenId,
@ -153,14 +155,14 @@ impl Cursive {
theme: theme, theme: theme,
screens: Vec::new(), screens: Vec::new(),
global_callbacks: HashMap::new(), global_callbacks: HashMap::new(),
menubar: view::Menubar::new(), menubar: views::Menubar::new(),
active_screen: 0, active_screen: 0,
running: true, running: true,
cb_source: rx, cb_source: rx,
cb_sink: tx, cb_sink: tx,
}; };
res.screens.push(StackView::new()); res.screens.push(views::StackView::new());
res res
} }
@ -237,7 +239,7 @@ impl Cursive {
/// siv.add_global_callback(Key::Esc, |s| s.select_menubar()); /// 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 &mut self.menubar
} }
@ -273,13 +275,13 @@ impl Cursive {
} }
/// Returns a reference to the currently active screen. /// Returns a reference to the currently active screen.
pub fn screen(&self) -> &StackView { pub fn screen(&self) -> &views::StackView {
let id = self.active_screen; let id = self.active_screen;
&self.screens[id] &self.screens[id]
} }
/// Returns a mutable reference to the currently active screen. /// 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; let id = self.active_screen;
self.screens.get_mut(id).unwrap() self.screens.get_mut(id).unwrap()
} }
@ -287,7 +289,7 @@ impl Cursive {
/// Adds a new screen, and returns its ID. /// Adds a new screen, and returns its ID.
pub fn add_screen(&mut self) -> ScreenId { pub fn add_screen(&mut self) -> ScreenId {
let res = self.screens.len(); let res = self.screens.len();
self.screens.push(StackView::new()); self.screens.push(views::StackView::new());
res res
} }
@ -309,7 +311,7 @@ impl Cursive {
self.active_screen = screen_id; 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. // Internal find method that returns a Any object.
self.screen_mut().find(selector) self.screen_mut().find(selector)
} }
@ -336,14 +338,14 @@ impl Cursive {
/// }); /// });
/// # } /// # }
/// ``` /// ```
pub fn find<V: View + Any>(&mut self, sel: &Selector) -> Option<&mut V> { pub fn find<V: View + Any>(&mut self, sel: &view::Selector) -> Option<&mut V> {
match self.find_any(sel) { match self.find_any(sel) {
None => None, None => None,
Some(b) => b.downcast_mut::<V>(), Some(b) => b.downcast_mut::<V>(),
} }
} }
/// Convenient method to use `find` with a `Selector::Id`. /// Convenient method to use `find` with a `view::Selector::Id`.
/// ///
/// # Examples /// # Examples
/// ///
@ -363,7 +365,7 @@ impl Cursive {
/// # } /// # }
/// ``` /// ```
pub fn find_id<V: View + Any>(&mut self, id: &str) -> Option<&mut V> { pub fn find_id<V: View + Any>(&mut self, id: &str) -> Option<&mut V> {
self.find(&Selector::Id(id)) self.find(&view::Selector::Id(id))
} }
/// Adds a global callback. /// Adds a global callback.

View File

@ -8,8 +8,9 @@
pub use {Cursive, Printer, With}; pub use {Cursive, Printer, With};
pub use event::{Event, Key}; pub use event::{Event, Key};
pub use view::{BoxView, Button, Checkbox, Dialog, EditView, FullView, IdView, pub use view::{Identifiable, Selector, View};
Identifiable, KeyEventView, LinearLayout, ListView, Panel, pub use views::{BoxView, Button, Checkbox, Dialog, EditView, FullView,
ProgressBar, SelectView, Selector, TextView, View}; IdView, KeyEventView, LinearLayout, ListView, Panel,
ProgressBar, SelectView, TextView};
pub use vec::Vec2; pub use vec::Vec2;
pub use menu::MenuTree; pub use menu::MenuTree;

View File

@ -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. //! Views are the main building blocks of your UI.
//! //!
@ -46,26 +46,6 @@ mod view_path;
mod scroll; mod scroll;
// Views // 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; use std::any::Any;
@ -80,27 +60,7 @@ pub use self::position::{Offset, Position};
pub use self::scroll::ScrollBase; 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::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; pub use self::view_wrapper::ViewWrapper;
@ -218,7 +178,7 @@ impl SizeCache {
/// ///
/// * `size` must fit inside `req`. /// * `size` must fit inside `req`.
/// * for each dimension, `constrained = (size == req)` /// * for each dimension, `constrained = (size == req)`
fn build(size: Vec2, req: Vec2) -> XY<Self> { pub fn build(size: Vec2, req: Vec2) -> XY<Self> {
XY::new(SizeCache::new(size.x, size.x >= req.x), XY::new(SizeCache::new(size.x, size.x >= req.x),
SizeCache::new(size.y, size.y >= req.y)) SizeCache::new(size.y, size.y >= req.y))
} }
@ -232,3 +192,13 @@ pub enum Selector<'a> {
/// Selects a view from its path. /// Selects a view from its path.
Path(&'a ViewPath), 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<Self> {
::views::IdView::new(id, self)
}
}
impl<T: View> Identifiable for T {}

View File

@ -2,7 +2,7 @@ use std::cmp;
use XY; use XY;
use vec::Vec2; use vec::Vec2;
use super::{View, ViewWrapper}; use view::{View, ViewWrapper};
/// Wrapper around another view, with a fixed size. /// Wrapper around another view, with a fixed size.
/// ///
@ -17,7 +17,7 @@ use super::{View, ViewWrapper};
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use cursive::view::{BoxView,TextView}; /// # use cursive::views::{BoxView,TextView};
/// // Creates a 20x4 BoxView with a TextView content. /// // Creates a 20x4 BoxView with a TextView content.
/// let view = BoxView::fixed_size((20,4), TextView::new("Hello!")); /// let view = BoxView::fixed_size((20,4), TextView::new("Hello!"));
/// ``` /// ```

View File

@ -7,8 +7,8 @@ use direction::Direction;
use align::*; use align::*;
use event::*; use event::*;
use theme::ColorStyle; use theme::ColorStyle;
use view::{DummyView, Selector, TextView, View}; use view::{DummyView, Selector, View};
use view::{Button, SizedView}; use views::{Button, SizedView, TextView};
use vec::{Vec2, Vec4}; use vec::{Vec2, Vec4};
use Printer; use Printer;
@ -25,7 +25,7 @@ enum Focus {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use cursive::view::{Dialog,TextView}; /// # use cursive::views::{Dialog,TextView};
/// let dialog = Dialog::new(TextView::new("Hello!")) /// let dialog = Dialog::new(TextView::new("Hello!"))
/// .button("Ok", |s| s.quit()); /// .button("Ok", |s| s.quit());
/// ``` /// ```

View File

@ -28,13 +28,3 @@ impl<T: View + Any> ViewWrapper for IdView<T> {
} }
} }
} }
/// 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<Self> {
IdView::new(id, self)
}
}
impl<T: View> Identifiable for T {}

View File

@ -2,7 +2,7 @@ use std::collections::HashMap;
use Cursive; use Cursive;
use event::{Callback, Event, EventResult}; 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. /// A simple wrapper view that catches some ignored event from its child.
/// ///

View File

@ -4,7 +4,7 @@ use vec::Vec2;
use view::View; use view::View;
use view::Selector; use view::Selector;
use direction; use direction;
use view::scroll::ScrollBase; use view::ScrollBase;
use event::{Event, EventResult, Key}; use event::{Event, EventResult, Key};
use std::any::Any; use std::any::Any;

View File

@ -7,10 +7,8 @@ use Cursive;
use With; use With;
use menu::{MenuItem, MenuTree}; use menu::{MenuItem, MenuTree};
use Printer; use Printer;
use view::View; use view::{View, Position, ScrollBase};
use view::Position; use views::KeyEventView;
use view::KeyEventView;
use view::scroll::ScrollBase;
use align::Align; use align::Align;
use vec::Vec2; use vec::Vec2;
use event::{Callback, Event, EventResult, Key}; use event::{Callback, Event, EventResult, Key};

View File

@ -1,15 +1,12 @@
use Cursive; use Cursive;
use view::View; use view::{View, Position};
use vec::Vec2; use vec::Vec2;
use direction; use direction;
use menu::MenuTree; use menu::MenuTree;
use backend::Backend; use backend::Backend;
use view::MenuPopup; use views::{MenuPopup, KeyEventView};
use view::KeyEventView;
use theme::ColorStyle; use theme::ColorStyle;
use Printer; use Printer;
use view::Position;
use event::*; use event::*;
use std::rc::Rc; use std::rc::Rc;

43
src/views/mod.rs Normal file
View File

@ -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;

View File

@ -3,14 +3,12 @@ use std::rc::Rc;
use std::cell::Cell; use std::cell::Cell;
use Cursive; use Cursive;
use menu::MenuTree;
use view::MenuPopup;
use With; use With;
use menu::MenuTree;
use direction::Direction; use direction::Direction;
use view::position::Position; use view::{Position, ScrollBase, View};
use view::{IdView, View}; use views::{IdView, MenuPopup};
use align::{Align, HAlign, VAlign}; use align::{Align, HAlign, VAlign};
use view::scroll::ScrollBase;
use event::{Callback, Event, EventResult, Key}; use event::{Callback, Event, EventResult, Key};
use theme::ColorStyle; use theme::ColorStyle;
use vec::Vec2; use vec::Vec2;

View File

@ -3,7 +3,8 @@ use std::any::Any;
use direction::Direction; use direction::Direction;
use backend::Backend; use backend::Backend;
use vec::Vec2; use vec::Vec2;
use view::{Offset, Position, Selector, ShadowView, View}; use view::{Offset, Position, Selector, View};
use views::ShadowView;
use event::{Event, EventResult}; use event::{Event, EventResult};
use Printer; use Printer;
use theme::ColorStyle; use theme::ColorStyle;

View File

@ -2,12 +2,11 @@ use XY;
use With; use With;
use direction::Direction; use direction::Direction;
use vec::Vec2; use vec::Vec2;
use view::View; use view::{View, SizeCache};
use view::SizeCache;
use Printer; use Printer;
use align::*; use align::*;
use event::*; use event::*;
use super::scroll::ScrollBase; use view::ScrollBase;
use utils::head_bytes; use utils::head_bytes;

View File

@ -1,6 +1,7 @@
use std::cell::Cell; use std::cell::Cell;
use view::{IdView, View, ViewWrapper}; use view::{View, ViewWrapper};
use views::IdView;
use Printer; use Printer;
use vec::Vec2; use vec::Vec2;