mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Move views to new views
module
This commit is contained in:
parent
51a1a19f92
commit
f87d0e7c5b
@ -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;
|
||||
|
28
src/lib.rs
28
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<StackView>,
|
||||
screens: Vec<views::StackView>,
|
||||
global_callbacks: HashMap<Event, Callback>,
|
||||
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<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) {
|
||||
None => None,
|
||||
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
|
||||
///
|
||||
@ -363,7 +365,7 @@ impl Cursive {
|
||||
/// # }
|
||||
/// ```
|
||||
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.
|
||||
|
@ -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;
|
||||
|
@ -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<Self> {
|
||||
pub fn build(size: Vec2, req: Vec2) -> XY<Self> {
|
||||
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<Self> {
|
||||
::views::IdView::new(id, self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: View> Identifiable for T {}
|
||||
|
@ -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!"));
|
||||
/// ```
|
@ -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());
|
||||
/// ```
|
@ -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 {}
|
@ -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.
|
||||
///
|
@ -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;
|
@ -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};
|
@ -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;
|
43
src/views/mod.rs
Normal file
43
src/views/mod.rs
Normal 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;
|
@ -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;
|
@ -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;
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user