2015-05-23 17:33:29 +00:00
|
|
|
use std::any::Any;
|
|
|
|
|
2016-06-28 05:10:59 +00:00
|
|
|
use view::{Selector, View, ViewWrapper};
|
2015-05-23 17:33:29 +00:00
|
|
|
|
|
|
|
/// Wrapper view that allows to select its content with a fixed string id.
|
|
|
|
pub struct IdView<T: View> {
|
|
|
|
view: T,
|
|
|
|
id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: View> IdView<T> {
|
|
|
|
/// Wraps the given view. It will be selectable with the given id.
|
|
|
|
pub fn new(id: &str, view: T) -> Self {
|
|
|
|
IdView {
|
|
|
|
view: view,
|
|
|
|
id: id.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-25 23:36:22 +00:00
|
|
|
impl<T: View + Any> ViewWrapper for IdView<T> {
|
2016-09-20 00:11:00 +00:00
|
|
|
wrap_impl!(self.view: T);
|
2015-05-23 17:33:29 +00:00
|
|
|
|
2017-02-07 02:18:17 +00:00
|
|
|
fn wrap_find_any<'a>(&mut self, selector: &Selector,
|
|
|
|
mut callback: Box<FnMut(&mut Any) + 'a>) {
|
2015-05-23 17:33:29 +00:00
|
|
|
match selector {
|
2017-02-07 02:18:17 +00:00
|
|
|
&Selector::Id(id) if id == self.id => callback(&mut self.view),
|
|
|
|
s => self.view.find_any(s, callback),
|
2015-05-23 17:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-25 21:50:52 +00:00
|
|
|
|
|
|
|
fn wrap_focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
|
|
|
match selector {
|
|
|
|
&Selector::Id(id) if id == self.id => Ok(()),
|
|
|
|
s => self.view.focus_view(s),
|
|
|
|
}
|
|
|
|
}
|
2015-05-23 17:33:29 +00:00
|
|
|
}
|