From 9aee7d374c41209881de31d6ed70eded12c5238c Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 6 Jan 2020 11:51:50 -0800 Subject: [PATCH] Rename some types BoxView => ResizedView SizedView => LastSizeView ViewBox => BoxedView Boxable => Resizable Boxable::box => Resizable::resize Old names are still re-exported, but deprecated. --- doc/tutorial_3.md | 20 ++--- examples/edit.rs | 4 +- examples/select.rs | 2 +- examples/select_test.rs | 2 +- examples/tcp_server.rs | 1 + src/traits.rs | 5 +- src/view/boxable.rs | 79 ---------------- src/view/identifiable.rs | 8 +- src/view/mod.rs | 7 +- src/view/resizable.rs | 89 +++++++++++++++++++ src/view/size_constraint.rs | 6 +- src/views/{view_box.rs => boxed_view.rs} | 16 ++-- src/views/dialog.rs | 12 +-- .../{sized_view.rs => last_size_view.rs} | 8 +- src/views/mod.rs | 24 +++-- src/views/{box_view.rs => resized_view.rs} | 72 ++++++++------- src/views/stack_view.rs | 12 +-- src/views/text_area.rs | 4 +- 18 files changed, 204 insertions(+), 167 deletions(-) delete mode 100644 src/view/boxable.rs create mode 100644 src/view/resizable.rs rename src/views/{view_box.rs => boxed_view.rs} (77%) rename src/views/{sized_view.rs => last_size_view.rs} (81%) rename src/views/{box_view.rs => resized_view.rs} (80%) diff --git a/doc/tutorial_3.md b/doc/tutorial_3.md index 8db57ea..5ffb74e 100644 --- a/doc/tutorial_3.md +++ b/doc/tutorial_3.md @@ -95,16 +95,16 @@ Our list will start empty. If we leave it like that, it will be tiny when the application starts, and will grow when we add names. This is not very professional-looking, so we'll give it a fixed size. -To do that, a [`BoxView`] can wrap any view and give it a fixed size. +To do that, a [`ResizedView`] can wrap any view and give it a fixed size. We could do: ```rust,ignore -let select = BoxView::with_fixed_size((10, 5), SelectView::::new()); +let select = ResizedView::with_fixed_size((10, 5), SelectView::::new()); ``` -But there is another shorter way: the [`Boxable`] trait is conveniently -implemented for any `View`, and allow to wrap in a `BoxView` with a chainable -call. `Boxable`, and a few other useful traits, are conveniently bundled in +But there is another shorter way: the [`Resizable`] trait is conveniently +implemented for any `View`, and allow to wrap in a `ResizedView` with a chainable +call. `Resizable`, and a few other useful traits, are conveniently bundled in the [`traits`] prelude, ready to be imported: ```rust,ignore @@ -133,14 +133,14 @@ fn on_submit(s: &mut Cursive, name: &str) { ``` (Be sure to call `on_submit` on the `SelectView`, -not on the `BoxView` returned by `fixed_size`!) +not on the `ResizedView` returned by `fixed_size`!) What we do there should be pretty familiar by now: replace the layer with a simple dialog. [`SelectView`]: https://docs.rs/cursive/0/cursive/views/struct.SelectView.html -[`BoxView`]: https://docs.rs/cursive/0/cursive/views/struct.BoxView.html -[`Boxable`]: https://docs.rs/cursive/0/cursive/view/trait.Boxable.html +[`ResizedView`]: https://docs.rs/cursive/0/cursive/views/struct.ResizedView.html +[`Resizable`]: https://docs.rs/cursive/0/cursive/view/trait.Resizable.html [`traits`]: https://docs.rs/cursive/0/cursive/traits/index.html [`SelectView::on_submit`]: https://docs.rs/cursive/0/cursive/views/struct.SelectView.html#method.on_submit @@ -228,7 +228,7 @@ how to point to the correct view. Later, you can ask the Cursive root for this ID and get access to the view. Just what we need! -Like `BoxView`, `IdView` can be used directly with [`IdView::new`], or through +Like `ResizedView`, `IdView` can be used directly with [`IdView::new`], or through the [`Identifiable`] trait. [`Cursive::call_on_id`] allows you to run a closure on the view. @@ -264,7 +264,7 @@ let select = SelectView::::new() .fixed_size((10, 5)); ``` (Here again, the order is important: we want to wrap the `SelectView`, not -the `BoxView`. But we still need to call `on_submit` before that.) +the `ResizedView`. But we still need to call `on_submit` before that.) That way, we can update it with a new item: diff --git a/examples/edit.rs b/examples/edit.rs index e7429c9..62c95e4 100644 --- a/examples/edit.rs +++ b/examples/edit.rs @@ -19,9 +19,9 @@ fn main() { .on_submit(show_popup) // Give the `EditView` a name so we can refer to it later. .with_id("name") - // Wrap this in a `BoxView` with a fixed width. + // Wrap this in a `ResizedView` with a fixed width. // Do this _after_ `with_id` or the name will point to the - // `BoxView` instead of `EditView`! + // `ResizedView` instead of `EditView`! .fixed_width(20), ) .button("Ok", |s| { diff --git a/examples/select.rs b/examples/select.rs index 521aaf4..7d70021 100644 --- a/examples/select.rs +++ b/examples/select.rs @@ -37,7 +37,7 @@ fn main() { let mut siv = Cursive::default(); - // Let's add a BoxView to keep the list at a reasonable size + // Let's add a ResizedView to keep the list at a reasonable size // (it can scroll anyway). siv.add_layer( Dialog::around(select.scrollable().fixed_size((20, 10))) diff --git a/examples/select_test.rs b/examples/select_test.rs index 62198df..ef6d75c 100644 --- a/examples/select_test.rs +++ b/examples/select_test.rs @@ -65,7 +65,7 @@ pub mod tests { let input = backend.input(); let mut siv = Cursive::new(|| backend); - // Let's add a BoxView to keep the list at a reasonable size + // Let's add a ResizedView to keep the list at a reasonable size // (it can scroll anyway). siv.add_layer( Dialog::around(select.scrollable().fixed_size((20, 10))) diff --git a/examples/tcp_server.rs b/examples/tcp_server.rs index 86f7fc6..95a1258 100644 --- a/examples/tcp_server.rs +++ b/examples/tcp_server.rs @@ -1,3 +1,4 @@ +use cursive::traits::Boxable; use cursive::traits::*; use cursive::views; diff --git a/src/traits.rs b/src/traits.rs index c75359e..76d0590 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -9,7 +9,10 @@ //! ``` #[doc(no_inline)] -pub use crate::view::{Boxable, Finder, Identifiable, Scrollable, View}; +#[allow(deprecated)] +pub use crate::view::{ + Boxable, Finder, Identifiable, Resizable, Scrollable, View, +}; #[doc(no_inline)] pub use crate::With; diff --git a/src/view/boxable.rs b/src/view/boxable.rs deleted file mode 100644 index 97a0296..0000000 --- a/src/view/boxable.rs +++ /dev/null @@ -1,79 +0,0 @@ -use crate::vec::Vec2; -use crate::view::{SizeConstraint, View}; -use crate::views::BoxView; - -/// Makes a view wrappable in a [`BoxView`]. -/// -/// [`BoxView`]: ../views/struct.BoxView.html -pub trait Boxable: View + Sized { - /// Wraps `self` in a `BoxView` with the given size constraints. - fn boxed( - self, - width: SizeConstraint, - height: SizeConstraint, - ) -> BoxView { - BoxView::new(width, height, self) - } - - /// Wraps `self` into a fixed-size `BoxView`. - fn fixed_size>(self, size: S) -> BoxView { - BoxView::with_fixed_size(size, self) - } - - /// Wraps `self` into a fixed-width `BoxView`. - fn fixed_width(self, width: usize) -> BoxView { - BoxView::with_fixed_width(width, self) - } - - /// Wraps `self` into a fixed-width `BoxView`. - fn fixed_height(self, height: usize) -> BoxView { - BoxView::with_fixed_height(height, self) - } - - /// Wraps `self` into a full-screen `BoxView`. - fn full_screen(self) -> BoxView { - BoxView::with_full_screen(self) - } - - /// Wraps `self` into a full-width `BoxView`. - fn full_width(self) -> BoxView { - BoxView::with_full_width(self) - } - - /// Wraps `self` into a full-height `BoxView`. - fn full_height(self) -> BoxView { - BoxView::with_full_height(self) - } - - /// Wraps `self` into a limited-size `BoxView`. - fn max_size>(self, size: S) -> BoxView { - BoxView::with_max_size(size, self) - } - - /// Wraps `self` into a limited-width `BoxView`. - fn max_width(self, max_width: usize) -> BoxView { - BoxView::with_max_width(max_width, self) - } - - /// Wraps `self` into a limited-height `BoxView`. - fn max_height(self, max_height: usize) -> BoxView { - BoxView::with_max_height(max_height, self) - } - - /// Wraps `self` into a `BoxView` at least sized `size`. - fn min_size>(self, size: S) -> BoxView { - BoxView::with_min_size(size, self) - } - - /// Wraps `self` in a `BoxView` at least `min_width` wide. - fn min_width(self, min_width: usize) -> BoxView { - BoxView::with_min_width(min_width, self) - } - - /// Wraps `self` in a `BoxView` at least `min_height` tall. - fn min_height(self, min_height: usize) -> BoxView { - BoxView::with_min_height(min_height, self) - } -} - -impl Boxable for T {} diff --git a/src/view/identifiable.rs b/src/view/identifiable.rs index 7b0567d..4d6610c 100644 --- a/src/view/identifiable.rs +++ b/src/view/identifiable.rs @@ -16,7 +16,7 @@ pub trait Identifiable: View + Sized { /// ```rust /// # use cursive::Cursive; /// # use cursive::views::TextView; - /// # use cursive::view::Boxable; + /// # use cursive::view::Resizable; /// use cursive::view::Identifiable; /// /// let mut siv = Cursive::dummy(); @@ -36,10 +36,10 @@ pub trait Identifiable: View + Sized { /// /// You should call this directly on the view you want to retrieve later, /// before other wrappers like [`fixed_width`]. Otherwise, you would be - /// retrieving a [`BoxView`]! + /// retrieving a [`ResizedView`]! /// - /// [`fixed_width`]: trait.Boxable.html#method.fixed_width - /// [`BoxView`]: ../views/struct.BoxView.html + /// [`fixed_width`]: trait.Resizable.html#method.fixed_width + /// [`ResizedView`]: ../views/struct.ResizedView.html /// fn with_id>(self, id: S) -> IdView { IdView::new(id, self) diff --git a/src/view/mod.rs b/src/view/mod.rs index a3c8071..9939266 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -93,8 +93,8 @@ mod view_path; mod view_trait; // Helper bases -mod boxable; mod identifiable; +mod resizable; #[macro_use] pub mod scroll; @@ -104,12 +104,12 @@ mod scrollable; mod into_boxed_view; pub use self::any::AnyView; -pub use self::boxable::Boxable; pub use self::finder::{Finder, Selector}; pub use self::identifiable::Identifiable; pub use self::into_boxed_view::IntoBoxedView; pub use self::margins::Margins; pub use self::position::{Offset, Position}; +pub use self::resizable::Resizable; pub use self::scroll::ScrollStrategy; pub use self::scroll_base::ScrollBase; pub use self::scrollable::Scrollable; @@ -118,3 +118,6 @@ pub use self::size_constraint::SizeConstraint; pub use self::view_path::ViewPath; pub use self::view_trait::View; pub use self::view_wrapper::ViewWrapper; + +#[deprecated(note = "Boxable is being renamed to Resizable")] +pub use self::resizable::Resizable as Boxable; diff --git a/src/view/resizable.rs b/src/view/resizable.rs new file mode 100644 index 0000000..aa8a2d0 --- /dev/null +++ b/src/view/resizable.rs @@ -0,0 +1,89 @@ +use crate::vec::Vec2; +use crate::view::{SizeConstraint, View}; +use crate::views::ResizedView; + +/// Makes a view wrappable in a [`ResizedView`]. +/// +/// [`ResizedView`]: ../views/struct.ResizedView.html +pub trait Resizable: View + Sized { + /// Same as [`resized`](Self::resized()) + #[deprecated(note = "Use resized() instead.")] + fn boxed( + self, + width: SizeConstraint, + height: SizeConstraint, + ) -> ResizedView { + self.resized(width, height) + } + + /// Wraps `self` in a `ResizedView` with the given size constraints. + fn resized( + self, + width: SizeConstraint, + height: SizeConstraint, + ) -> ResizedView { + ResizedView::new(width, height, self) + } + + /// Wraps `self` into a fixed-size `ResizedView`. + fn fixed_size>(self, size: S) -> ResizedView { + ResizedView::with_fixed_size(size, self) + } + + /// Wraps `self` into a fixed-width `ResizedView`. + fn fixed_width(self, width: usize) -> ResizedView { + ResizedView::with_fixed_width(width, self) + } + + /// Wraps `self` into a fixed-width `ResizedView`. + fn fixed_height(self, height: usize) -> ResizedView { + ResizedView::with_fixed_height(height, self) + } + + /// Wraps `self` into a full-screen `ResizedView`. + fn full_screen(self) -> ResizedView { + ResizedView::with_full_screen(self) + } + + /// Wraps `self` into a full-width `ResizedView`. + fn full_width(self) -> ResizedView { + ResizedView::with_full_width(self) + } + + /// Wraps `self` into a full-height `ResizedView`. + fn full_height(self) -> ResizedView { + ResizedView::with_full_height(self) + } + + /// Wraps `self` into a limited-size `ResizedView`. + fn max_size>(self, size: S) -> ResizedView { + ResizedView::with_max_size(size, self) + } + + /// Wraps `self` into a limited-width `ResizedView`. + fn max_width(self, max_width: usize) -> ResizedView { + ResizedView::with_max_width(max_width, self) + } + + /// Wraps `self` into a limited-height `ResizedView`. + fn max_height(self, max_height: usize) -> ResizedView { + ResizedView::with_max_height(max_height, self) + } + + /// Wraps `self` into a `ResizedView` at least sized `size`. + fn min_size>(self, size: S) -> ResizedView { + ResizedView::with_min_size(size, self) + } + + /// Wraps `self` in a `ResizedView` at least `min_width` wide. + fn min_width(self, min_width: usize) -> ResizedView { + ResizedView::with_min_width(min_width, self) + } + + /// Wraps `self` in a `ResizedView` at least `min_height` tall. + fn min_height(self, min_height: usize) -> ResizedView { + ResizedView::with_min_height(min_height, self) + } +} + +impl Resizable for T {} diff --git a/src/view/size_constraint.rs b/src/view/size_constraint.rs index dfaca5f..a5b0a5d 100644 --- a/src/view/size_constraint.rs +++ b/src/view/size_constraint.rs @@ -2,9 +2,9 @@ use std::cmp::min; /// Single-dimensional constraint on a view size. /// -/// This describes a possible behaviour for a [`BoxView`]. +/// This describes a possible behaviour for a [`ResizedView`]. /// -/// [`BoxView`]: ../views/struct.BoxView.html +/// [`ResizedView`]: ../views/struct.ResizedView.html #[derive(Debug, Clone, Copy)] pub enum SizeConstraint { /// No constraint imposed, the child view's response is used. @@ -22,7 +22,7 @@ pub enum SizeConstraint { impl SizeConstraint { /// Returns the size to be given to the child. /// - /// When `available` is offered to the `BoxView`. + /// When `available` is offered to the `ResizedView`. pub fn available(self, available: usize) -> usize { match self { SizeConstraint::Free diff --git a/src/views/view_box.rs b/src/views/boxed_view.rs similarity index 77% rename from src/views/view_box.rs rename to src/views/boxed_view.rs index 7af45fc..970f0df 100644 --- a/src/views/view_box.rs +++ b/src/views/boxed_view.rs @@ -4,14 +4,14 @@ use std::ops::{Deref, DerefMut}; /// A boxed `View`. /// /// It derefs to the wrapped view. -pub struct ViewBox { +pub struct BoxedView { view: Box, } -impl ViewBox { - /// Creates a new `ViewBox` around the given boxed view. +impl BoxedView { + /// Creates a new `BoxedView` around the given boxed view. pub fn new(view: Box) -> Self { - ViewBox { view } + BoxedView { view } } /// Box the given view @@ -19,7 +19,7 @@ impl ViewBox { where T: IntoBoxedView, { - ViewBox::new(view.as_boxed_view()) + BoxedView::new(view.as_boxed_view()) } /// Returns the inner boxed view. @@ -28,7 +28,7 @@ impl ViewBox { } } -impl Deref for ViewBox { +impl Deref for BoxedView { type Target = dyn View; fn deref(&self) -> &dyn View { @@ -36,13 +36,13 @@ impl Deref for ViewBox { } } -impl DerefMut for ViewBox { +impl DerefMut for BoxedView { fn deref_mut(&mut self) -> &mut dyn View { &mut *self.view } } -impl ViewWrapper for ViewBox { +impl ViewWrapper for BoxedView { type V = dyn View; fn with_view(&self, f: F) -> Option diff --git a/src/views/dialog.rs b/src/views/dialog.rs index 8e76b38..98408b4 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -5,7 +5,7 @@ use crate::rect::Rect; use crate::theme::ColorStyle; use crate::vec::Vec2; use crate::view::{Margins, Selector, View}; -use crate::views::{Button, DummyView, SizedView, TextView, ViewBox}; +use crate::views::{BoxedView, Button, DummyView, LastSizeView, TextView}; use crate::Cursive; use crate::Printer; use crate::With; @@ -25,7 +25,7 @@ pub enum DialogFocus { } struct ChildButton { - button: SizedView