mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add with_id_mut
and find_id_mut
convenient methods.
This commit is contained in:
parent
1de7dcd819
commit
1b8d109e94
12
src/lib.rs
12
src/lib.rs
@ -427,6 +427,18 @@ impl Cursive {
|
||||
self.find(&view::Selector::Id(id), callback)
|
||||
}
|
||||
|
||||
/// Convenient method to find a view wrapped in [`RefCellView`].
|
||||
///
|
||||
/// This looks for a `RefCellView<V>` with the given ID, and return
|
||||
/// a mutable reference to the wrapped view.
|
||||
///
|
||||
/// [`RefCellView`]: views/struct.RefCellView.html
|
||||
pub fn find_id_mut<V>(&mut self, id: &str) -> Option<views::ViewRef<V>>
|
||||
where V: View + Any
|
||||
{
|
||||
self.find_id(id, views::RefCellView::<V>::get_mut)
|
||||
}
|
||||
|
||||
/// Adds a global callback.
|
||||
///
|
||||
/// Will be triggered on the given key press when no view catches it.
|
||||
|
@ -1,16 +1,26 @@
|
||||
use view::View;
|
||||
use views::IdView;
|
||||
use views::{IdView, RefCellView};
|
||||
|
||||
/// Makes a view wrappable in an [`IdView`].
|
||||
///
|
||||
/// [`IdView`]: ../views/struct.IdView.html
|
||||
pub trait Identifiable: View + Sized {
|
||||
/// Wraps this view into an IdView with the given id.
|
||||
/// Wraps this view into an `IdView` with the given id.
|
||||
///
|
||||
/// This is just a shortcut for `IdView::new(id, self)`
|
||||
fn with_id(self, id: &str) -> IdView<Self> {
|
||||
IdView::new(id, self)
|
||||
}
|
||||
|
||||
/// Wraps this view into both a [`RefCellView`] and an `IdView`.
|
||||
///
|
||||
/// This allows to call [`Cursive::find_id_mut`].
|
||||
///
|
||||
/// [`RefCellView`]: ../views/struct.RefCellView.html
|
||||
/// [`Cursive::find_id_mut`]: ../struct.Cursive.html#method.find_id_mut
|
||||
fn with_id_mut(self, id: &str) -> IdView<RefCellView<Self>> {
|
||||
RefCellView::new(self).with_id(id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Any `View` implements this trait.
|
||||
|
Loading…
Reference in New Issue
Block a user