diff --git a/src/view/mod.rs b/src/view/mod.rs index 51481ab..56201ce 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -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) { + fn find_any<'a>(&mut self, _: &Selector, _: Box) { // TODO: FnMut -> FnOnce once it works } @@ -176,8 +176,11 @@ impl 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::() { - *result_ref = Some(callback(v)); + if v.is::() { + *result_ref = v.downcast_mut::().map(|v| callback(v)); + } else if v.is::>() { + *result_ref = v.downcast_mut::>() + .and_then(|v| v.with_view_mut(callback)); } }; self.find_any(sel, Box::new(callback)); diff --git a/src/views/text_view.rs b/src/views/text_view.rs index 9a88578..0d49de2 100644 --- a/src/views/text_view.rs +++ b/src/views/text_view.rs @@ -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>(self, content: S) -> Self { + self.with(|s| s.set_content(content)) + } + /// Replace the text in this view. pub fn set_content>(&mut self, content: S) { let content = content.into();