mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Better documentation for view::Finder
Also adds `Finder::find_id`
This commit is contained in:
parent
f879305d7f
commit
a5135a7aff
@ -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.
|
||||
|
@ -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};
|
||||
|
@ -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<V: View>` 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<V: View + Any>(&mut self, sel: &Selector) -> Option<&mut V>;
|
||||
|
||||
/// Convenient method to use `find` with a `view::Selector::Id`.
|
||||
fn find_id<V: View + Any>(&mut self, id: &str) -> Option<&mut V> {
|
||||
self.find(&Selector::Id(id))
|
||||
}
|
||||
}
|
||||
|
||||
impl <T: View> Finder for T {
|
||||
|
Loading…
Reference in New Issue
Block a user