diff --git a/src/lib.rs b/src/lib.rs index 38436b1..3a48122 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -321,7 +321,7 @@ impl Cursive { self.active_screen = screen_id; } - /// Tries to find the view pointed to by the given path. + /// Tries to find the view pointed to by the given selector. /// /// If the view is not found, or if it is not of the asked type, /// it returns None. diff --git a/src/prelude.rs b/src/prelude.rs index 2254f14..3c21524 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -8,7 +8,7 @@ pub use {Cursive, Printer, With}; pub use event::{Event, Key}; -pub use view::{Boxable, Identifiable, Selector, View}; +pub use view::{Boxable, Finder, Identifiable, Selector, View}; pub use views::{BoxView, Button, Checkbox, Dialog, DummyView, EditView, IdView, KeyEventView, LinearLayout, ListView, Panel, ProgressBar, SelectView, SliderView, TextArea, TextView}; diff --git a/src/view/mod.rs b/src/view/mod.rs index 6f26d9e..dee0391 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -115,6 +115,10 @@ pub trait View { /// Finds the view pointed to by the given path. /// + /// See [`Finder::find`] for a nicer interface, implemented for all views. + /// + /// [`Finder::find`]: trait.Finder.html#method.find + /// /// Returns None if the path doesn't lead to a view. /// /// Default implementation always return `None`. @@ -135,10 +139,24 @@ pub trait View { } /// Provides `find` to views. +/// +/// This trait is mostly a wrapper around [`View::find_any`]. +/// +/// It provides a nicer interface to find a view when you know its type. +/// +/// [`View::find_any`]: ./trait.View.html#method.find_any pub trait Finder { - /// Find a view + /// Tries to find the view pointed to by the given selector. + /// + /// If the view is not found, or if it is not of the asked type, + /// it returns None. fn find(&mut self, sel: &Selector) -> Option<&mut V>; + + /// Convenient method to use `find` with a `view::Selector::Id`. + fn find_id(&mut self, id: &str) -> Option<&mut V> { + self.find(&Selector::Id(id)) + } } impl Finder for T {