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 direction::Direction;
|
||||||
use event::{Event, EventResult};
|
use event::{Event, EventResult};
|
||||||
use std::any::Any;
|
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
use views::RefCellView;
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
/// Main trait defining a view behaviour.
|
/// Main trait defining a view behaviour.
|
||||||
pub trait View {
|
pub trait View {
|
||||||
@ -122,8 +123,7 @@ pub trait View {
|
|||||||
/// Returns None if the path doesn't lead to a view.
|
/// Returns None if the path doesn't lead to a view.
|
||||||
///
|
///
|
||||||
/// Default implementation always return `None`.
|
/// Default implementation always return `None`.
|
||||||
fn find_any<'a>(&mut self, _: &Selector,
|
fn find_any<'a>(&mut self, _: &Selector, _: Box<FnMut(&mut Any) + 'a>) {
|
||||||
_: Box<FnMut(&mut Any) + 'a>) {
|
|
||||||
// TODO: FnMut -> FnOnce once it works
|
// TODO: FnMut -> FnOnce once it works
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,8 +176,11 @@ impl<T: View> Finder for T {
|
|||||||
let mut callback = Some(callback);
|
let mut callback = Some(callback);
|
||||||
let callback = |v: &mut Any| if let Some(callback) =
|
let callback = |v: &mut Any| if let Some(callback) =
|
||||||
callback.take() {
|
callback.take() {
|
||||||
if let Some(v) = v.downcast_mut::<V>() {
|
if v.is::<V>() {
|
||||||
*result_ref = Some(callback(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));
|
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.
|
/// Enable or disable the view's scrolling capabilities.
|
||||||
///
|
///
|
||||||
/// When disabled, the view will never attempt to scroll
|
/// When disabled, the view will never attempt to scroll
|
||||||
@ -98,6 +103,13 @@ impl TextView {
|
|||||||
self
|
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.
|
/// Replace the text in this view.
|
||||||
pub fn set_content<S: Into<String>>(&mut self, content: S) {
|
pub fn set_content<S: Into<String>>(&mut self, content: S) {
|
||||||
let content = content.into();
|
let content = content.into();
|
||||||
|
Loading…
Reference in New Issue
Block a user