Rename some types

BoxView => ResizedView
SizedView => LastSizeView
ViewBox => BoxedView
Boxable => Resizable
Boxable::box => Resizable::resize

Old names are still re-exported, but deprecated.
This commit is contained in:
Alexandre Bury 2020-01-06 11:51:50 -08:00
parent 237c6c8e33
commit 9aee7d374c
18 changed files with 204 additions and 167 deletions

View File

@ -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::<String>::new());
let select = ResizedView::with_fixed_size((10, 5), SelectView::<String>::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::<String>::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:

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
use cursive::traits::Boxable;
use cursive::traits::*;
use cursive::views;

View File

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

View File

@ -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<Self> {
BoxView::new(width, height, self)
}
/// Wraps `self` into a fixed-size `BoxView`.
fn fixed_size<S: Into<Vec2>>(self, size: S) -> BoxView<Self> {
BoxView::with_fixed_size(size, self)
}
/// Wraps `self` into a fixed-width `BoxView`.
fn fixed_width(self, width: usize) -> BoxView<Self> {
BoxView::with_fixed_width(width, self)
}
/// Wraps `self` into a fixed-width `BoxView`.
fn fixed_height(self, height: usize) -> BoxView<Self> {
BoxView::with_fixed_height(height, self)
}
/// Wraps `self` into a full-screen `BoxView`.
fn full_screen(self) -> BoxView<Self> {
BoxView::with_full_screen(self)
}
/// Wraps `self` into a full-width `BoxView`.
fn full_width(self) -> BoxView<Self> {
BoxView::with_full_width(self)
}
/// Wraps `self` into a full-height `BoxView`.
fn full_height(self) -> BoxView<Self> {
BoxView::with_full_height(self)
}
/// Wraps `self` into a limited-size `BoxView`.
fn max_size<S: Into<Vec2>>(self, size: S) -> BoxView<Self> {
BoxView::with_max_size(size, self)
}
/// Wraps `self` into a limited-width `BoxView`.
fn max_width(self, max_width: usize) -> BoxView<Self> {
BoxView::with_max_width(max_width, self)
}
/// Wraps `self` into a limited-height `BoxView`.
fn max_height(self, max_height: usize) -> BoxView<Self> {
BoxView::with_max_height(max_height, self)
}
/// Wraps `self` into a `BoxView` at least sized `size`.
fn min_size<S: Into<Vec2>>(self, size: S) -> BoxView<Self> {
BoxView::with_min_size(size, self)
}
/// Wraps `self` in a `BoxView` at least `min_width` wide.
fn min_width(self, min_width: usize) -> BoxView<Self> {
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<Self> {
BoxView::with_min_height(min_height, self)
}
}
impl<T: View> Boxable for T {}

View File

@ -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<S: Into<String>>(self, id: S) -> IdView<Self> {
IdView::new(id, self)

View File

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

89
src/view/resizable.rs Normal file
View File

@ -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> {
self.resized(width, height)
}
/// Wraps `self` in a `ResizedView` with the given size constraints.
fn resized(
self,
width: SizeConstraint,
height: SizeConstraint,
) -> ResizedView<Self> {
ResizedView::new(width, height, self)
}
/// Wraps `self` into a fixed-size `ResizedView`.
fn fixed_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self> {
ResizedView::with_fixed_size(size, self)
}
/// Wraps `self` into a fixed-width `ResizedView`.
fn fixed_width(self, width: usize) -> ResizedView<Self> {
ResizedView::with_fixed_width(width, self)
}
/// Wraps `self` into a fixed-width `ResizedView`.
fn fixed_height(self, height: usize) -> ResizedView<Self> {
ResizedView::with_fixed_height(height, self)
}
/// Wraps `self` into a full-screen `ResizedView`.
fn full_screen(self) -> ResizedView<Self> {
ResizedView::with_full_screen(self)
}
/// Wraps `self` into a full-width `ResizedView`.
fn full_width(self) -> ResizedView<Self> {
ResizedView::with_full_width(self)
}
/// Wraps `self` into a full-height `ResizedView`.
fn full_height(self) -> ResizedView<Self> {
ResizedView::with_full_height(self)
}
/// Wraps `self` into a limited-size `ResizedView`.
fn max_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self> {
ResizedView::with_max_size(size, self)
}
/// Wraps `self` into a limited-width `ResizedView`.
fn max_width(self, max_width: usize) -> ResizedView<Self> {
ResizedView::with_max_width(max_width, self)
}
/// Wraps `self` into a limited-height `ResizedView`.
fn max_height(self, max_height: usize) -> ResizedView<Self> {
ResizedView::with_max_height(max_height, self)
}
/// Wraps `self` into a `ResizedView` at least sized `size`.
fn min_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self> {
ResizedView::with_min_size(size, self)
}
/// Wraps `self` in a `ResizedView` at least `min_width` wide.
fn min_width(self, min_width: usize) -> ResizedView<Self> {
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<Self> {
ResizedView::with_min_height(min_height, self)
}
}
impl<T: View> Resizable for T {}

View File

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

View File

@ -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<dyn View>,
}
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<dyn View>) -> 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<F, R>(&self, f: F) -> Option<R>

View File

@ -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<Button>,
button: LastSizeView<Button>,
offset: Cell<Vec2>,
}
@ -35,7 +35,7 @@ impl ChildButton {
F: 'static + Fn(&mut Cursive),
{
ChildButton {
button: SizedView::new(Button::new(label, cb)),
button: LastSizeView::new(Button::new(label, cb)),
offset: Cell::new(Vec2::zero()),
}
}
@ -58,7 +58,7 @@ pub struct Dialog {
title_position: HAlign,
// The actual inner view.
content: SizedView<ViewBox>,
content: LastSizeView<BoxedView>,
// Optional list of buttons under the main view.
// Include the top-left corner.
@ -93,7 +93,7 @@ impl Dialog {
/// Creates a new `Dialog` with the given content.
pub fn around<V: View + 'static>(view: V) -> Self {
Dialog {
content: SizedView::new(ViewBox::boxed(view)),
content: LastSizeView::new(BoxedView::boxed(view)),
buttons: Vec::new(),
title: String::new(),
title_position: HAlign::Center,
@ -148,7 +148,7 @@ impl Dialog {
///
/// Previous content will be dropped.
pub fn set_content<V: View + 'static>(&mut self, view: V) {
self.content = SizedView::new(ViewBox::boxed(view));
self.content = LastSizeView::new(BoxedView::boxed(view));
self.invalidate();
}

View File

@ -3,17 +3,17 @@ use crate::view::View;
use crate::view::ViewWrapper;
/// Wrapper around a view that remembers its size.
pub struct SizedView<T> {
pub struct LastSizeView<T> {
/// Wrapped view.
pub view: T,
/// Cached size from the last layout() call.
pub size: Vec2,
}
impl<T> SizedView<T> {
impl<T> LastSizeView<T> {
/// Wraps the given view.
pub fn new(view: T) -> Self {
SizedView {
LastSizeView {
view,
size: Vec2::zero(),
}
@ -22,7 +22,7 @@ impl<T> SizedView<T> {
inner_getters!(self.view: T);
}
impl<T: View> ViewWrapper for SizedView<T> {
impl<T: View> ViewWrapper for LastSizeView<T> {
wrap_impl!(self.view: T);
fn wrap_layout(&mut self, size: Vec2) {

View File

@ -52,7 +52,7 @@ macro_rules! impl_enabled {
}
}
mod box_view;
mod boxed_view;
mod button;
mod canvas;
mod checkbox;
@ -64,6 +64,7 @@ mod edit_view;
mod enableable_view;
mod hideable_view;
mod id_view;
mod last_size_view;
mod layer;
mod linear_layout;
mod list_view;
@ -74,18 +75,17 @@ mod padded_view;
mod panel;
mod progress_bar;
mod radio;
mod resized_view;
mod scroll_view;
mod select_view;
mod shadow_view;
mod sized_view;
mod slider_view;
mod stack_view;
mod text_area;
mod text_view;
mod tracked_view;
mod view_box;
pub use self::box_view::BoxView;
pub use self::boxed_view::BoxedView;
pub use self::button::Button;
pub use self::canvas::Canvas;
pub use self::checkbox::Checkbox;
@ -97,6 +97,7 @@ pub use self::edit_view::EditView;
pub use self::enableable_view::EnableableView;
pub use self::hideable_view::HideableView;
pub use self::id_view::{IdView, ViewRef};
pub use self::last_size_view::LastSizeView;
pub use self::layer::Layer;
pub use self::linear_layout::LinearLayout;
pub use self::list_view::{ListChild, ListView};
@ -107,13 +108,24 @@ pub use self::padded_view::PaddedView;
pub use self::panel::Panel;
pub use self::progress_bar::ProgressBar;
pub use self::radio::{RadioButton, RadioGroup};
pub use self::resized_view::ResizedView;
pub use self::scroll_view::ScrollView;
pub use self::select_view::SelectView;
pub use self::shadow_view::ShadowView;
pub use self::sized_view::SizedView;
pub use self::slider_view::SliderView;
pub use self::stack_view::{LayerPosition, StackView};
pub use self::text_area::TextArea;
pub use self::text_view::{TextContent, TextContentRef, TextView};
pub use self::tracked_view::TrackedView;
pub use self::view_box::ViewBox;
#[deprecated(note = "SizedView is being renamed to LastSizeView")]
/// Same as [`LastSizeView`](self::LastSizeView).
pub type SizedView<T> = LastSizeView<T>;
#[deprecated(note = "BoxView is being renamed to ResizedView")]
/// Same as [`ResizedView`](self::ResizedView).
pub type BoxView<T> = ResizedView<T>;
#[deprecated(note = "ViewBox is being renamed to BoxedView")]
/// Same as [`BoxedView`](self::BoxedView).
pub type ViewBox = BoxedView;

View File

@ -16,14 +16,14 @@ use crate::XY;
/// # Examples
///
/// ```
/// use cursive::views::{BoxView, TextView};
/// use cursive::views::{ResizedView, TextView};
///
/// // Creates a 20x4 BoxView with a TextView content.
/// let view = BoxView::with_fixed_size((20,4), TextView::new("Hello!"));
/// // Creates a 20x4 ResizedView with a TextView content.
/// let view = ResizedView::with_fixed_size((20,4), TextView::new("Hello!"));
/// ```
///
/// See also [`Boxable`](crate::view::Boxable) for an easy way to wrap any view.
pub struct BoxView<T: View> {
pub struct ResizedView<T: View> {
/// Constraint on each axis
size: XY<SizeConstraint>,
@ -34,8 +34,8 @@ pub struct BoxView<T: View> {
view: T,
}
impl<T: View> BoxView<T> {
/// Creates a new `BoxView` with the given width and height requirements.
impl<T: View> ResizedView<T> {
/// Creates a new `ResizedView` with the given width and height requirements.
///
/// `None` values will use the wrapped view's preferences.
pub fn new(
@ -43,7 +43,7 @@ impl<T: View> BoxView<T> {
height: SizeConstraint,
view: T,
) -> Self {
BoxView {
ResizedView {
size: (width, height).into(),
invalidated: true,
view,
@ -76,102 +76,110 @@ impl<T: View> BoxView<T> {
self.invalidate();
}
/// Wraps `view` in a new `BoxView` with the given size.
/// Wraps `view` in a new `ResizedView` with the given size.
pub fn with_fixed_size<S: Into<Vec2>>(size: S, view: T) -> Self {
let size = size.into();
BoxView::new(
ResizedView::new(
SizeConstraint::Fixed(size.x),
SizeConstraint::Fixed(size.y),
view,
)
}
/// Wraps `view` in a new `BoxView` with fixed width.
/// Wraps `view` in a new `ResizedView` with fixed width.
pub fn with_fixed_width(width: usize, view: T) -> Self {
BoxView::new(SizeConstraint::Fixed(width), SizeConstraint::Free, view)
ResizedView::new(
SizeConstraint::Fixed(width),
SizeConstraint::Free,
view,
)
}
/// Wraps `view` in a new `BoxView` with fixed height.
/// Wraps `view` in a new `ResizedView` with fixed height.
pub fn with_fixed_height(height: usize, view: T) -> Self {
BoxView::new(SizeConstraint::Free, SizeConstraint::Fixed(height), view)
ResizedView::new(
SizeConstraint::Free,
SizeConstraint::Fixed(height),
view,
)
}
/// Wraps `view` in a `BoxView` which will take all available space.
/// Wraps `view` in a `ResizedView` which will take all available space.
pub fn with_full_screen(view: T) -> Self {
BoxView::new(SizeConstraint::Full, SizeConstraint::Full, view)
ResizedView::new(SizeConstraint::Full, SizeConstraint::Full, view)
}
/// Wraps `view` in a `BoxView` which will take all available width.
/// Wraps `view` in a `ResizedView` which will take all available width.
pub fn with_full_width(view: T) -> Self {
BoxView::new(SizeConstraint::Full, SizeConstraint::Free, view)
ResizedView::new(SizeConstraint::Full, SizeConstraint::Free, view)
}
/// Wraps `view` in a `BoxView` which will take all available height.
/// Wraps `view` in a `ResizedView` which will take all available height.
pub fn with_full_height(view: T) -> Self {
BoxView::new(SizeConstraint::Free, SizeConstraint::Full, view)
ResizedView::new(SizeConstraint::Free, SizeConstraint::Full, view)
}
/// Wraps `view` in a `BoxView` which will never be bigger than `size`.
/// Wraps `view` in a `ResizedView` which will never be bigger than `size`.
pub fn with_max_size<S: Into<Vec2>>(size: S, view: T) -> Self {
let size = size.into();
BoxView::new(
ResizedView::new(
SizeConstraint::AtMost(size.x),
SizeConstraint::AtMost(size.y),
view,
)
}
/// Wraps `view` in a `BoxView` which will enforce a maximum width.
/// Wraps `view` in a `ResizedView` which will enforce a maximum width.
///
/// The resulting width will never be more than `max_width`.
pub fn with_max_width(max_width: usize, view: T) -> Self {
BoxView::new(
ResizedView::new(
SizeConstraint::AtMost(max_width),
SizeConstraint::Free,
view,
)
}
/// Wraps `view` in a `BoxView` which will enforce a maximum height.
/// Wraps `view` in a `ResizedView` which will enforce a maximum height.
///
/// The resulting height will never be more than `max_height`.
pub fn with_max_height(max_height: usize, view: T) -> Self {
BoxView::new(
ResizedView::new(
SizeConstraint::Free,
SizeConstraint::AtMost(max_height),
view,
)
}
/// Wraps `view` in a `BoxView` which will never be smaller than `size`.
/// Wraps `view` in a `ResizedView` which will never be smaller than `size`.
pub fn with_min_size<S: Into<Vec2>>(size: S, view: T) -> Self {
let size = size.into();
BoxView::new(
ResizedView::new(
SizeConstraint::AtLeast(size.x),
SizeConstraint::AtLeast(size.y),
view,
)
}
/// Wraps `view` in a `BoxView` which will enforce a minimum width.
/// Wraps `view` in a `ResizedView` which will enforce a minimum width.
///
/// The resulting width will never be less than `min_width`.
pub fn with_min_width(min_width: usize, view: T) -> Self {
BoxView::new(
ResizedView::new(
SizeConstraint::AtLeast(min_width),
SizeConstraint::Free,
view,
)
}
/// Wraps `view` in a `BoxView` which will enforce a minimum height.
/// Wraps `view` in a `ResizedView` which will enforce a minimum height.
///
/// The resulting height will never be less than `min_height`.
pub fn with_min_height(min_height: usize, view: T) -> Self {
BoxView::new(
ResizedView::new(
SizeConstraint::Free,
SizeConstraint::AtLeast(min_height),
view,
@ -186,7 +194,7 @@ impl<T: View> BoxView<T> {
inner_getters!(self.view: T);
}
impl<T: View> ViewWrapper for BoxView<T> {
impl<T: View> ViewWrapper for ResizedView<T> {
wrap_impl!(self.view: T);
fn wrap_draw(&self, printer: &Printer) {

View File

@ -5,7 +5,7 @@ use crate::vec::Vec2;
use crate::view::{
IntoBoxedView, Offset, Position, Selector, View, ViewWrapper,
};
use crate::views::{CircularFocus, Layer, ShadowView, ViewBox};
use crate::views::{BoxedView, CircularFocus, Layer, ShadowView};
use crate::Printer;
use crate::With;
use std::cell;
@ -199,7 +199,7 @@ impl<T: View> View for ChildWrapper<T> {
}
struct Child {
view: ChildWrapper<ViewBox>,
view: ChildWrapper<BoxedView>,
size: Vec2,
placement: Placement,
@ -250,7 +250,7 @@ impl StackView {
where
T: IntoBoxedView,
{
let boxed = ViewBox::boxed(view);
let boxed = BoxedView::boxed(view);
self.layers.push(Child {
view: ChildWrapper::Backfilled(Layer::new(
CircularFocus::wrap_tab(boxed),
@ -356,7 +356,7 @@ impl StackView {
where
T: IntoBoxedView,
{
let boxed = ViewBox::boxed(view);
let boxed = BoxedView::boxed(view);
self.layers.push(Child {
// Skip padding for absolute/parent-placed views
view: ChildWrapper::Shadow(
@ -383,7 +383,7 @@ impl StackView {
where
T: IntoBoxedView,
{
let boxed = ViewBox::boxed(view);
let boxed = BoxedView::boxed(view);
self.layers.push(Child {
view: ChildWrapper::Plain(CircularFocus::wrap_tab(boxed)),
size: Vec2::new(0, 0),
@ -419,7 +419,7 @@ impl StackView {
.pop()
.map(|child| child.view)
.map(ChildWrapper::unwrap)
.map(ViewBox::unwrap)
.map(BoxedView::unwrap)
}
/// Computes the offset of the current top view.

View File

@ -14,13 +14,13 @@ use unicode_width::UnicodeWidthStr;
/// Multi-lines text editor.
///
/// A `TextArea` will attempt to grow vertically and horizontally
/// dependent on the content. Wrap it in a `BoxView` to
/// dependent on the content. Wrap it in a `ResizedView` to
/// constrain its size.
///
/// # Examples
///
/// ```
/// use cursive::traits::{Boxable, Identifiable};
/// use cursive::traits::{Resizable, Identifiable};
/// use cursive::views::TextArea;
///
/// let text_area = TextArea::new()