Add PaddedView::get_inner(_mut) and fix clippy warnings

This commit is contained in:
Alexandre Bury 2019-10-25 19:46:49 -07:00
parent 985e4ebf96
commit 884796fb02
8 changed files with 18 additions and 48 deletions

View File

@ -334,12 +334,10 @@ impl Cursive {
/// ///
/// ```rust /// ```rust
/// # use cursive::*; /// # use cursive::*;
/// # fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// // quit() will be called during the next event cycle /// // quit() will be called during the next event cycle
/// siv.cb_sink().send(Box::new(|s| s.quit())).unwrap(); /// siv.cb_sink().send(Box::new(|s| s.quit())).unwrap();
/// # }
/// ``` /// ```
pub fn cb_sink(&self) -> &CbSink { pub fn cb_sink(&self) -> &CbSink {
&self.cb_sink &self.cb_sink
@ -370,7 +368,6 @@ impl Cursive {
/// # use cursive::traits::*; /// # use cursive::traits::*;
/// # use cursive::menu::*; /// # use cursive::menu::*;
/// # /// #
/// # fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// siv.menubar() /// siv.menubar()
@ -404,7 +401,6 @@ impl Cursive {
/// |s| s.add_layer(Dialog::info("Cursive v0.0.0")))); /// |s| s.add_layer(Dialog::info("Cursive v0.0.0"))));
/// ///
/// siv.add_global_callback(event::Key::Esc, |s| s.select_menubar()); /// siv.add_global_callback(event::Key::Esc, |s| s.select_menubar());
/// # }
/// ``` /// ```
pub fn menubar(&mut self) -> &mut views::Menubar { pub fn menubar(&mut self) -> &mut views::Menubar {
&mut self.menubar &mut self.menubar
@ -526,8 +522,6 @@ impl Cursive {
/// ```rust /// ```rust
/// # use cursive::{Cursive, views, view}; /// # use cursive::{Cursive, views, view};
/// # use cursive::traits::*; /// # use cursive::traits::*;
/// # fn main() {
/// fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// siv.add_layer(views::TextView::new("Text #1").with_id("text")); /// siv.add_layer(views::TextView::new("Text #1").with_id("text"));
@ -540,9 +534,6 @@ impl Cursive {
/// }, /// },
/// ); /// );
/// }); /// });
///
/// }
/// # }
/// ``` /// ```
pub fn call_on<V, F, R>( pub fn call_on<V, F, R>(
&mut self, &mut self,
@ -565,7 +556,6 @@ impl Cursive {
/// ```rust /// ```rust
/// # use cursive::{Cursive, views}; /// # use cursive::{Cursive, views};
/// # use cursive::traits::*; /// # use cursive::traits::*;
/// # fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// siv.add_layer(views::TextView::new("Text #1") /// siv.add_layer(views::TextView::new("Text #1")
@ -576,7 +566,6 @@ impl Cursive {
/// view.set_content("Text #2"); /// view.set_content("Text #2");
/// }); /// });
/// }); /// });
/// # }
/// ``` /// ```
pub fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R> pub fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R>
where where
@ -658,11 +647,9 @@ impl Cursive {
/// ///
/// ```rust /// ```rust
/// # use cursive::*; /// # use cursive::*;
/// # fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// siv.add_global_callback('q', |s| s.quit()); /// siv.add_global_callback('q', |s| s.quit());
/// # }
/// ``` /// ```
pub fn add_global_callback<F, E: Into<Event>>(&mut self, event: E, cb: F) pub fn add_global_callback<F, E: Into<Event>>(&mut self, event: E, cb: F)
where where
@ -679,13 +666,11 @@ impl Cursive {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// # use cursive::*; /// use cursive::Cursive;
/// # fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// siv.add_global_callback('q', |s| s.quit()); /// siv.add_global_callback('q', |s| s.quit());
/// siv.clear_global_callbacks('q'); /// siv.clear_global_callbacks('q');
/// # }
/// ``` /// ```
pub fn clear_global_callbacks<E>(&mut self, event: E) pub fn clear_global_callbacks<E>(&mut self, event: E)
where where
@ -700,12 +685,10 @@ impl Cursive {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// # use cursive::*; /// use cursive::{Cursive, views};
/// # fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// siv.add_layer(views::TextView::new("Hello world!")); /// siv.add_layer(views::TextView::new("Hello world!"));
/// # }
/// ``` /// ```
pub fn add_layer<T>(&mut self, view: T) pub fn add_layer<T>(&mut self, view: T)
where where

View File

@ -36,7 +36,6 @@
//! use cursive::Cursive; //! use cursive::Cursive;
//! use cursive::views::TextView; //! use cursive::views::TextView;
//! //!
//! fn main() {
//! let mut siv = Cursive::dummy(); //! let mut siv = Cursive::dummy();
//! //!
//! siv.add_layer(TextView::new("Hello World!\nPress q to quit.")); //! siv.add_layer(TextView::new("Hello World!\nPress q to quit."));
@ -44,7 +43,6 @@
//! siv.add_global_callback('q', |s| s.quit()); //! siv.add_global_callback('q', |s| s.quit());
//! //!
//! siv.run(); //! siv.run();
//! }
//! ``` //! ```
//! //!
//! ## Debugging //! ## Debugging

View File

@ -42,12 +42,10 @@ pub fn make_lines(content: &str, width: usize) -> Vec<Row> {
/// use unicode_segmentation::UnicodeSegmentation; /// use unicode_segmentation::UnicodeSegmentation;
/// ///
/// # use cursive::utils::lines::simple::prefix; /// # use cursive::utils::lines::simple::prefix;
/// # fn main() {
/// let my_text = "blah..."; /// let my_text = "blah...";
/// // This returns the number of bytes for a prefix of `my_text` that /// // This returns the number of bytes for a prefix of `my_text` that
/// // fits within 5 cells. /// // fits within 5 cells.
/// prefix(my_text.graphemes(true), 5, ""); /// prefix(my_text.graphemes(true), 5, "");
/// # }
/// ``` /// ```
pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Span pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Span
where where

View File

@ -20,10 +20,8 @@ pub trait AnyView {
/// ```rust /// ```rust
/// # use cursive::views::TextView; /// # use cursive::views::TextView;
/// # use cursive::view::View; /// # use cursive::view::View;
/// # fn main() {
/// let boxed: Box<View> = Box::new(TextView::new("text")); /// let boxed: Box<View> = Box::new(TextView::new("text"));
/// let text: Box<TextView> = boxed.as_boxed_any().downcast().unwrap(); /// let text: Box<TextView> = boxed.as_boxed_any().downcast().unwrap();
/// # }
/// ``` /// ```
fn as_boxed_any(self: Box<Self>) -> Box<dyn Any>; fn as_boxed_any(self: Box<Self>) -> Box<dyn Any>;
} }

View File

@ -34,7 +34,6 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
/// # use cursive::Cursive; /// # use cursive::Cursive;
/// # use cursive::traits::*; /// # use cursive::traits::*;
/// # use cursive::views::{Dialog, EditView, TextView}; /// # use cursive::views::{Dialog, EditView, TextView};
/// # fn main() {
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// ///
/// // Create a dialog with an edit text and a button. /// // Create a dialog with an edit text and a button.
@ -69,8 +68,6 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
/// .button("Quit", |s| s.quit())); /// .button("Quit", |s| s.quit()));
/// } /// }
/// } /// }
///
/// # }
/// ``` /// ```
pub struct EditView { pub struct EditView {
/// Current content. /// Current content.

View File

@ -25,6 +25,8 @@ pub struct PaddedView<V> {
} }
impl<V: View> PaddedView<V> { impl<V: View> PaddedView<V> {
inner_getters!(self.view: V);
/// Wraps `view` in a new `PaddedView` with the given margins. /// Wraps `view` in a new `PaddedView` with the given margins.
pub fn new<M: Into<Margins>>(margins: M, view: V) -> Self { pub fn new<M: Into<Margins>>(margins: M, view: V) -> Self {
let margins = margins.into(); let margins = margins.into();

View File

@ -28,7 +28,6 @@ use std::rc::Rc;
/// # use cursive::Cursive; /// # use cursive::Cursive;
/// # use cursive::views::{SelectView, Dialog, TextView}; /// # use cursive::views::{SelectView, Dialog, TextView};
/// # use cursive::align::HAlign; /// # use cursive::align::HAlign;
/// # fn main() {
/// let mut time_select = SelectView::new().h_align(HAlign::Center); /// let mut time_select = SelectView::new().h_align(HAlign::Center);
/// time_select.add_item("Short", 1); /// time_select.add_item("Short", 1);
/// time_select.add_item("Medium", 5); /// time_select.add_item("Medium", 5);
@ -44,8 +43,6 @@ use std::rc::Rc;
/// let mut siv = Cursive::dummy(); /// let mut siv = Cursive::dummy();
/// siv.add_layer(Dialog::around(time_select) /// siv.add_layer(Dialog::around(time_select)
/// .title("How long is your wait?")); /// .title("How long is your wait?"));
/// # }
///
/// ``` /// ```
pub struct SelectView<T = String> { pub struct SelectView<T = String> {
// The core of the view: we store a list of items // The core of the view: we store a list of items
@ -586,7 +583,6 @@ impl<T: 'static> SelectView<T> {
/// ```rust /// ```rust
/// # use cursive::Cursive; /// # use cursive::Cursive;
/// # use cursive::views::SelectView; /// # use cursive::views::SelectView;
/// # fn main() {}
/// fn select_up(siv: &mut Cursive, view: &mut SelectView<()>) { /// fn select_up(siv: &mut Cursive, view: &mut SelectView<()>) {
/// let cb = view.select_up(1); /// let cb = view.select_up(1);
/// cb(siv); /// cb(siv);

View File

@ -310,14 +310,12 @@ impl StackView {
/// ```rust /// ```rust
/// # use cursive::views::{TextView, StackView, Dialog, LayerPosition}; /// # use cursive::views::{TextView, StackView, Dialog, LayerPosition};
/// # use cursive::view::Identifiable; /// # use cursive::view::Identifiable;
/// # fn main() {
/// let mut stack = StackView::new(); /// let mut stack = StackView::new();
/// stack.add_layer(TextView::new("Back")); /// stack.add_layer(TextView::new("Back"));
/// stack.add_layer(Dialog::around(TextView::new("Middle").with_id("text"))); /// stack.add_layer(Dialog::around(TextView::new("Middle").with_id("text")));
/// stack.add_layer(TextView::new("Front")); /// stack.add_layer(TextView::new("Front"));
/// ///
/// assert_eq!(stack.find_layer_from_id("text"), Some(LayerPosition::FromBack(1))); /// assert_eq!(stack.find_layer_from_id("text"), Some(LayerPosition::FromBack(1)));
/// # }
/// ``` /// ```
pub fn find_layer_from_id(&mut self, id: &str) -> Option<LayerPosition> { pub fn find_layer_from_id(&mut self, id: &str) -> Option<LayerPosition> {
let selector = Selector::Id(id); let selector = Selector::Id(id);