Remove FullView

This commit is contained in:
Alexandre Bury 2016-08-04 20:03:48 -07:00
parent 8a09702f66
commit e79cc61e08
5 changed files with 8 additions and 73 deletions

View File

@ -23,9 +23,7 @@ fn main() {
}); });
// And sets the view to read from the other end of the channel. // And sets the view to read from the other end of the channel.
// (We use FullView to force fullscreen because siv.add_layer(BufferView::new(200, rx).full_screen());
// we have no min_size for the BufferView).
siv.add_layer(FullView::new(BufferView::new(200, rx)));
siv.run(); siv.run();
} }

View File

@ -44,7 +44,7 @@ fn phase_1(s: &mut Cursive) {
let cb = s.cb_sink().clone(); let cb = s.cb_sink().clone();
s.pop_layer(); s.pop_layer();
s.add_layer(Panel::new(FullView::full_width(ProgressBar::new() s.add_layer(Panel::new(ProgressBar::new()
.range(0, n_max) .range(0, n_max)
.with_task(move |counter| { .with_task(move |counter| {
// This closure will be called in a separate thread. // This closure will be called in a separate thread.
@ -52,7 +52,8 @@ fn phase_1(s: &mut Cursive) {
// When we're done, send a callback through the channel // When we're done, send a callback through the channel
cb.send(Box::new(coffee_break)).unwrap(); cb.send(Box::new(coffee_break)).unwrap();
})))); })
.full_width()));
} }
fn coffee_break(s: &mut Cursive) { fn coffee_break(s: &mut Cursive) {
@ -87,7 +88,7 @@ fn phase_2(s: &mut Cursive) {
} }
s.pop_layer(); s.pop_layer();
s.add_layer(Dialog::new(FullView::full_width(linear)) s.add_layer(Dialog::new(linear.full_width())
.title("Just a moment...")); .title("Just a moment..."));
// And we start the worker thread. // And we start the worker thread.

View File

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

View File

@ -1,62 +0,0 @@
use view::{View, ViewWrapper};
use direction::Orientation;
use vec::Vec2;
/// Simple wrapper view that asks for all the space it can get.
///
/// # Examples
///
/// ```
/// # use cursive::prelude::*;
/// let view = FullView::new(TextView::new("Big box for little text!"));
/// ```
pub struct FullView<T: View> {
view: T,
orientation: Option<Orientation>,
}
impl<T: View> FullView<T> {
/// Wraps the given view into a new FullView.
///
/// It will always take the entire space available.
pub fn new(view: T) -> Self {
FullView {
view: view,
orientation: None,
}
}
/// Creates a new wrapper around `view` with full width.
///
/// It will always take the maximum width available.
pub fn full_width(view: T) -> Self {
FullView {
view: view,
orientation: Some(Orientation::Horizontal),
}
}
/// Creates a new wrapper around `view` with full height.
///
/// It will always take the maximum height available.
pub fn full_height(view: T) -> Self {
FullView {
view: view,
orientation: Some(Orientation::Vertical),
}
}
}
impl<T: View> ViewWrapper for FullView<T> {
wrap_impl!(&self.view);
fn wrap_get_min_size(&mut self, mut req: Vec2) -> Vec2 {
if let Some(orientation) = self.orientation {
let child_size = self.view.get_min_size(req);
let orientation = orientation.swap();
*orientation.get_ref(&mut req) = orientation.get(&child_size);
}
req
}
}

View File

@ -6,7 +6,6 @@ mod checkbox;
mod dialog; mod dialog;
mod dummy; mod dummy;
mod edit_view; mod edit_view;
mod full_view;
mod id_view; mod id_view;
mod key_event_view; mod key_event_view;
mod linear_layout; mod linear_layout;
@ -30,7 +29,6 @@ pub use self::checkbox::Checkbox;
pub use self::dialog::Dialog; pub use self::dialog::Dialog;
pub use self::dummy::DummyView; pub use self::dummy::DummyView;
pub use self::edit_view::EditView; pub use self::edit_view::EditView;
pub use self::full_view::FullView;
pub use self::key_event_view::KeyEventView; pub use self::key_event_view::KeyEventView;
pub use self::linear_layout::LinearLayout; pub use self::linear_layout::LinearLayout;
pub use self::list_view::ListView; pub use self::list_view::ListView;