From c86eaa58754e0c77f30cedf7c4a2b5823a0f268c Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Wed, 6 Nov 2019 12:26:17 -0800 Subject: [PATCH] Big renaming: part 1 --- src/cursive.rs | 22 ++--- src/lib.rs | 2 + src/view/boxable.rs | 84 ++++++++--------- src/view/finder.rs | 12 +-- src/view/identifiable.rs | 14 +-- src/view/scrollable.rs | 12 +-- src/view/size_constraint.rs | 6 +- src/views/{view_box.rs => boxed.rs} | 16 ++-- src/views/{debug_view.rs => debug_console.rs} | 12 +-- src/views/dialog.rs | 32 +++---- src/views/dummy.rs | 4 +- src/views/{edit_view.rs => edit.rs} | 38 ++++---- .../{enableable_view.rs => enableable.rs} | 20 ++--- src/views/{hideable_view.rs => hideable.rs} | 14 +-- src/views/{sized_view.rs => last_size.rs} | 8 +- src/views/{list_view.rs => list.rs} | 16 ++-- src/views/menu_popup.rs | 4 +- src/views/menubar.rs | 6 +- src/views/mod.rs | 74 +++++++-------- src/views/{id_view.rs => named.rs} | 10 +-- src/views/{on_event_view.rs => on_event.rs} | 36 ++++---- src/views/{padded_view.rs => padded.rs} | 16 ++-- src/views/{box_view.rs => resized.rs} | 66 +++++++------- src/views/{scroll_view.rs => scroll.rs} | 14 +-- src/views/{select_view.rs => select.rs} | 90 +++++++++---------- src/views/{shadow_view.rs => shadow.rs} | 8 +- src/views/{slider_view.rs => slider.rs} | 18 ++-- src/views/{stack_view.rs => stack.rs} | 85 +++++++++--------- src/views/{text_view.rs => text.rs} | 38 ++++---- src/views/{tracked_view.rs => tracked.rs} | 18 ++-- 30 files changed, 397 insertions(+), 398 deletions(-) rename src/views/{view_box.rs => boxed.rs} (78%) rename src/views/{debug_view.rs => debug_console.rs} (93%) rename src/views/{edit_view.rs => edit.rs} (96%) rename src/views/{enableable_view.rs => enableable.rs} (72%) rename src/views/{hideable_view.rs => hideable.rs} (88%) rename src/views/{sized_view.rs => last_size.rs} (82%) rename src/views/{list_view.rs => list.rs} (98%) rename src/views/{id_view.rs => named.rs} (94%) rename src/views/{on_event_view.rs => on_event.rs} (90%) rename src/views/{padded_view.rs => padded.rs} (83%) rename src/views/{box_view.rs => resized.rs} (83%) rename src/views/{scroll_view.rs => scroll.rs} (96%) rename src/views/{select_view.rs => select.rs} (93%) rename src/views/{shadow_view.rs => shadow.rs} (95%) rename src/views/{slider_view.rs => slider.rs} (95%) rename src/views/{stack_view.rs => stack.rs} (91%) rename src/views/{text_view.rs => text.rs} (92%) rename src/views/{tracked_view.rs => tracked.rs} (67%) diff --git a/src/cursive.rs b/src/cursive.rs index 1c8695c..c0b84b1 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -32,7 +32,7 @@ type HashMap = std::collections::HashMap; /// It uses a list of screen, with one screen active at a time. pub struct Cursive { theme: theme::Theme, - screens: Vec, + screens: Vec, global_callbacks: HashMap>, menubar: views::Menubar, @@ -153,7 +153,7 @@ impl Cursive { backend_init().map(|backend| Cursive { theme, - screens: vec![views::StackView::new()], + screens: vec![views::Stack::new()], last_sizes: Vec::new(), global_callbacks: HashMap::default(), menubar: views::Menubar::new(), @@ -286,9 +286,9 @@ impl Cursive { pub fn show_debug_console(&mut self) { self.add_layer( views::Dialog::around( - views::ScrollView::new(views::IdView::new( + views::Scroll::new(views::Named::new( DEBUG_VIEW_ID, - views::DebugView::new(), + views::DebugConsole::new(), )) .scroll_x(true), ) @@ -466,13 +466,13 @@ impl Cursive { } /// Returns a reference to the currently active screen. - pub fn screen(&self) -> &views::StackView { + pub fn screen(&self) -> &views::Stack { let id = self.active_screen; &self.screens[id] } /// Returns a mutable reference to the currently active screen. - pub fn screen_mut(&mut self) -> &mut views::StackView { + pub fn screen_mut(&mut self) -> &mut views::Stack { let id = self.active_screen; &mut self.screens[id] } @@ -485,7 +485,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(views::StackView::new()); + self.screens.push(views::Stack::new()); res } @@ -575,9 +575,9 @@ impl Cursive { self.call_on(&view::Selector::Id(id), callback) } - /// Convenient method to find a view wrapped in [`IdView`]. + /// Convenient method to find a view wrapped in [`Named`]. /// - /// This looks for a `IdView` with the given ID, and return + /// This looks for a `Named` with the given ID, and return /// a [`ViewRef`] to the wrapped view. The `ViewRef` implements /// `DerefMut`, so you can treat it just like a `&mut T`. /// @@ -618,13 +618,13 @@ impl Cursive { /// assert!(siv.find_id::>("select").is_some()); /// ``` /// - /// [`IdView`]: views/struct.IdView.html + /// [`Named`]: views/struct.Named.html /// [`ViewRef`]: views/type.ViewRef.html pub fn find_id(&mut self, id: &str) -> Option> where V: View + Any, { - self.call_on_id(id, views::IdView::::get_mut) + self.call_on_id(id, views::Named::::get_mut) } /// Moves the focus to the view identified by `id`. diff --git a/src/lib.rs b/src/lib.rs index cc1ce16..8e12c48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,8 +101,10 @@ mod utf8; pub mod backend; pub use self::cursive::{CbSink, Cursive, ScreenId}; +pub use self::direction::Direction; pub use self::printer::Printer; pub use self::rect::Rect; pub use self::vec::Vec2; +pub use self::view::View; pub use self::with::With; pub use self::xy::XY; diff --git a/src/view/boxable.rs b/src/view/boxable.rs index 97a0296..db785f3 100644 --- a/src/view/boxable.rs +++ b/src/view/boxable.rs @@ -1,78 +1,78 @@ use crate::vec::Vec2; use crate::view::{SizeConstraint, View}; -use crate::views::BoxView; +use crate::views::Resized; -/// Makes a view wrappable in a [`BoxView`]. +/// Makes a view wrappable in a [`Resized`]. /// -/// [`BoxView`]: ../views/struct.BoxView.html +/// [`Resized`]: ../views/struct.Resized.html pub trait Boxable: View + Sized { - /// Wraps `self` in a `BoxView` with the given size constraints. + /// Wraps `self` in a `Resized` with the given size constraints. fn boxed( self, width: SizeConstraint, height: SizeConstraint, - ) -> BoxView { - BoxView::new(width, height, self) + ) -> Resized { + Resized::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-size `Resized`. + fn fixed_size>(self, size: S) -> Resized { + Resized::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 `Resized`. + fn fixed_width(self, width: usize) -> Resized { + Resized::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 fixed-width `Resized`. + fn fixed_height(self, height: usize) -> Resized { + Resized::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-screen `Resized`. + fn full_screen(self) -> Resized { + Resized::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-width `Resized`. + fn full_width(self) -> Resized { + Resized::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 full-height `Resized`. + fn full_height(self) -> Resized { + Resized::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-size `Resized`. + fn max_size>(self, size: S) -> Resized { + Resized::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-width `Resized`. + fn max_width(self, max_width: usize) -> Resized { + Resized::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 limited-height `Resized`. + fn max_height(self, max_height: usize) -> Resized { + Resized::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` into a `Resized` at least sized `size`. + fn min_size>(self, size: S) -> Resized { + Resized::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 `Resized` at least `min_width` wide. + fn min_width(self, min_width: usize) -> Resized { + Resized::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) + /// Wraps `self` in a `Resized` at least `min_height` tall. + fn min_height(self, min_height: usize) -> Resized { + Resized::with_min_height(min_height, self) } } diff --git a/src/view/finder.rs b/src/view/finder.rs index 8136d2b..b918616 100644 --- a/src/view/finder.rs +++ b/src/view/finder.rs @@ -1,5 +1,5 @@ use crate::view::{View, ViewPath, ViewWrapper}; -use crate::views::{IdView, ViewRef}; +use crate::views::{Named, ViewRef}; use std::any::Any; /// Provides `call_on` to views. @@ -34,14 +34,14 @@ pub trait Finder { self.call_on(&Selector::Id(id), callback) } - /// Convenient method to find a view wrapped in an [`IdView`]. + /// Convenient method to find a view wrapped in an [`Named`]. /// - /// [`IdView`]: views/struct.IdView.html + /// [`Named`]: views/struct.Named.html fn find_id(&mut self, id: &str) -> Option> where V: View + Any, { - self.call_on_id(id, IdView::::get_mut) + self.call_on_id(id, Named::::get_mut) } } @@ -65,9 +65,9 @@ impl Finder for T { if v.is::() { *result_ref = v.downcast_mut::().map(|v| callback(v)); - } else if v.is::>() { + } else if v.is::>() { *result_ref = v - .downcast_mut::>() + .downcast_mut::>() .and_then(|v| v.with_view_mut(callback)); } } diff --git a/src/view/identifiable.rs b/src/view/identifiable.rs index 7b0567d..50eba9c 100644 --- a/src/view/identifiable.rs +++ b/src/view/identifiable.rs @@ -1,13 +1,13 @@ use crate::view::View; -use crate::views::IdView; +use crate::views::Named; -/// Makes a view wrappable in an [`IdView`]. +/// Makes a view wrappable in an [`Named`]. /// -/// [`IdView`]: ../views/struct.IdView.html +/// [`Named`]: ../views/struct.Named.html pub trait Identifiable: View + Sized { - /// Wraps this view into an `IdView` with the given id. + /// Wraps this view into an `Named` with the given id. /// - /// This is just a shortcut for `IdView::new(id, self)` + /// This is just a shortcut for `Named::new(id, self)` /// /// You can use the given id to find the view in the layout tree. /// @@ -41,8 +41,8 @@ pub trait Identifiable: View + Sized { /// [`fixed_width`]: trait.Boxable.html#method.fixed_width /// [`BoxView`]: ../views/struct.BoxView.html /// - fn with_id>(self, id: S) -> IdView { - IdView::new(id, self) + fn with_id>(self, id: S) -> Named { + Named::new(id, self) } } diff --git a/src/view/scrollable.rs b/src/view/scrollable.rs index 0dcc586..4d1bd64 100644 --- a/src/view/scrollable.rs +++ b/src/view/scrollable.rs @@ -1,13 +1,13 @@ use crate::view::View; -use crate::views::ScrollView; +use crate::views::Scroll; -/// Makes a view wrappable in a [`ScrollView`]. +/// Makes a view wrappable in a [`Scroll`]. /// -/// [`ScrollView`]: crate::views::ScrollView +/// [`Scroll`]: crate::views::Scroll pub trait Scrollable: View + Sized { - /// Wraps `self` in a `ScrollView`. - fn scrollable(self) -> ScrollView { - ScrollView::new(self) + /// Wraps `self` in a `Scroll`. + fn scrollable(self) -> Scroll { + Scroll::new(self) } } diff --git a/src/view/size_constraint.rs b/src/view/size_constraint.rs index dfaca5f..83edc07 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 [`Resized`]. /// -/// [`BoxView`]: ../views/struct.BoxView.html +/// [`Resized`]: ../views/struct.Resized.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 `Resized`. pub fn available(self, available: usize) -> usize { match self { SizeConstraint::Free diff --git a/src/views/view_box.rs b/src/views/boxed.rs similarity index 78% rename from src/views/view_box.rs rename to src/views/boxed.rs index 7af45fc..dbe8523 100644 --- a/src/views/view_box.rs +++ b/src/views/boxed.rs @@ -4,14 +4,14 @@ use std::ops::{Deref, DerefMut}; /// A boxed `View`. /// /// It derefs to the wrapped view. -pub struct ViewBox { +pub struct Boxed { view: Box, } -impl ViewBox { - /// Creates a new `ViewBox` around the given boxed view. +impl Boxed { + /// Creates a new `Boxed` around the given boxed view. pub fn new(view: Box) -> Self { - ViewBox { view } + Boxed { view } } /// Box the given view @@ -19,7 +19,7 @@ impl ViewBox { where T: IntoBoxedView, { - ViewBox::new(view.as_boxed_view()) + Boxed::new(view.as_boxed_view()) } /// Returns the inner boxed view. @@ -28,7 +28,7 @@ impl ViewBox { } } -impl Deref for ViewBox { +impl Deref for Boxed { type Target = dyn View; fn deref(&self) -> &dyn View { @@ -36,13 +36,13 @@ impl Deref for ViewBox { } } -impl DerefMut for ViewBox { +impl DerefMut for Boxed { fn deref_mut(&mut self) -> &mut dyn View { &mut *self.view } } -impl ViewWrapper for ViewBox { +impl ViewWrapper for Boxed { type V = dyn View; fn with_view(&self, f: F) -> Option diff --git a/src/views/debug_view.rs b/src/views/debug_console.rs similarity index 93% rename from src/views/debug_view.rs rename to src/views/debug_console.rs index d41cfc5..ff2e197 100644 --- a/src/views/debug_view.rs +++ b/src/views/debug_console.rs @@ -7,24 +7,24 @@ use crate::Printer; use unicode_width::UnicodeWidthStr; /// View used for debugging, showing logs. -pub struct DebugView { +pub struct DebugConsole { // TODO: wrap log lines if needed, and save the line splits here. } -impl DebugView { - /// Creates a new DebugView. +impl DebugConsole { + /// Creates a new DebugConsole. pub fn new() -> Self { - DebugView {} + DebugConsole {} } } -impl Default for DebugView { +impl Default for DebugConsole { fn default() -> Self { Self::new() } } -impl View for DebugView { +impl View for DebugConsole { fn draw(&self, printer: &Printer<'_, '_>) { let logs = logger::LOGS.lock().unwrap(); // Only print the last logs, so skip what doesn't fit diff --git a/src/views/dialog.rs b/src/views/dialog.rs index 8e76b38..c51228e 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::{Boxed, Button, Dummy, LastSize, Text}; use crate::Cursive; use crate::Printer; use crate::With; @@ -25,7 +25,7 @@ pub enum DialogFocus { } struct ChildButton { - button: SizedView