use std::any::Any; use view::{Selector, View, ViewWrapper}; /// Wrapper view that allows to select its content with a fixed string id. pub struct IdView { view: T, id: String, } impl IdView { /// 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(), } } } impl ViewWrapper for IdView { wrap_impl!(self.view: T); fn wrap_find_any<'a>(&mut self, selector: &Selector, mut callback: Box) { match selector { &Selector::Id(id) if id == self.id => callback(&mut self.view), s => self.view.find_any(s, callback), } } 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), } } }