mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 01:46:31 +00:00
Add get_view for ViewWrapper (needs fix)
This commit is contained in:
parent
057321abac
commit
d0956b40b0
@ -39,6 +39,9 @@ pub trait ViewWrapper: 'static {
|
||||
where
|
||||
F: FnOnce(&mut Self::V) -> R;
|
||||
|
||||
/// Gets the reference to the wrapped view.
|
||||
fn get_view(&self) -> &Self::V;
|
||||
|
||||
/// Attempts to retrieve the inner view.
|
||||
fn into_inner(self) -> Result<Self::V, Self>
|
||||
where
|
||||
@ -119,6 +122,10 @@ where
|
||||
{
|
||||
Some(f(self.deref_mut()))
|
||||
}
|
||||
|
||||
fn get_view(&self) -> &Self::V {
|
||||
self.deref()
|
||||
}
|
||||
}
|
||||
|
||||
// The main point of implementing ViewWrapper is to have View for free.
|
||||
@ -196,8 +203,8 @@ macro_rules! wrap_impl {
|
||||
Some(f(&mut self.$v))
|
||||
}
|
||||
|
||||
fn into_inner(self) -> Result<Self::V, Self> where Self::V: Sized {
|
||||
Ok(self.$v)
|
||||
fn get_view(&self) -> &Self::V {
|
||||
&self.$v
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -263,4 +263,15 @@ mod tests {
|
||||
assert_eq!(Vec2::new(10, 1), full.required_size(Vec2::new(10, 1)));
|
||||
assert_eq!(Vec2::new(10, 10), full.required_size(Vec2::new(10, 10)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
//TODO: rm this or use it
|
||||
fn xxx() {
|
||||
use views::{BoxView,TextView};
|
||||
use view::{ViewWrapper};
|
||||
let parent: BoxView<TextView> = TextView::new("abc").full_screen();
|
||||
//let child: TextView = parent.view;
|
||||
let child: &TextView = parent.get_view();
|
||||
1/0;
|
||||
}
|
||||
}
|
||||
|
@ -99,4 +99,11 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
|
||||
.and_then(|mut v| v.deref_mut().focus_view(s)),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_view(&self) -> &Self::V {
|
||||
use std::ops::Deref;
|
||||
let view = self.view.try_borrow().unwrap()
|
||||
;
|
||||
view.deref()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user