mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
feat: find_id
can now find views declared with with_id_mut
This commit is contained in:
parent
b50d2f077f
commit
cb3adc5baf
@ -65,9 +65,10 @@ use Printer;
|
||||
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult};
|
||||
use std::any::Any;
|
||||
use vec::Vec2;
|
||||
use views::RefCellView;
|
||||
|
||||
use std::any::Any;
|
||||
|
||||
/// Main trait defining a view behaviour.
|
||||
pub trait View {
|
||||
@ -122,8 +123,7 @@ pub trait View {
|
||||
/// Returns None if the path doesn't lead to a view.
|
||||
///
|
||||
/// Default implementation always return `None`.
|
||||
fn find_any<'a>(&mut self, _: &Selector,
|
||||
_: Box<FnMut(&mut Any) + 'a>) {
|
||||
fn find_any<'a>(&mut self, _: &Selector, _: Box<FnMut(&mut Any) + 'a>) {
|
||||
// TODO: FnMut -> FnOnce once it works
|
||||
}
|
||||
|
||||
@ -176,8 +176,11 @@ impl<T: View> Finder for T {
|
||||
let mut callback = Some(callback);
|
||||
let callback = |v: &mut Any| if let Some(callback) =
|
||||
callback.take() {
|
||||
if let Some(v) = v.downcast_mut::<V>() {
|
||||
*result_ref = Some(callback(v));
|
||||
if v.is::<V>() {
|
||||
*result_ref = v.downcast_mut::<V>().map(|v| callback(v));
|
||||
} else if v.is::<RefCellView<V>>() {
|
||||
*result_ref = v.downcast_mut::<RefCellView<V>>()
|
||||
.and_then(|v| v.with_view_mut(callback));
|
||||
}
|
||||
};
|
||||
self.find_any(sel, Box::new(callback));
|
||||
|
@ -53,6 +53,11 @@ impl TextView {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new empty `TextView`.
|
||||
pub fn empty() -> Self {
|
||||
TextView::new("")
|
||||
}
|
||||
|
||||
/// Enable or disable the view's scrolling capabilities.
|
||||
///
|
||||
/// When disabled, the view will never attempt to scroll
|
||||
@ -98,6 +103,13 @@ impl TextView {
|
||||
self
|
||||
}
|
||||
|
||||
/// Replace the text in this view.
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn content<S: Into<String>>(self, content: S) -> Self {
|
||||
self.with(|s| s.set_content(content))
|
||||
}
|
||||
|
||||
/// Replace the text in this view.
|
||||
pub fn set_content<S: Into<String>>(&mut self, content: S) {
|
||||
let content = content.into();
|
||||
|
Loading…
Reference in New Issue
Block a user