Add non-boxed wrap_impl! macro

Although maybe sized_view should rather use a box internally.
This commit is contained in:
Alexandre Bury 2015-05-19 16:40:32 -07:00
parent c8136c67e0
commit 191c2899ea
4 changed files with 18 additions and 10 deletions

View File

@ -27,7 +27,7 @@ impl BoxView {
impl ViewWrapper for BoxView { impl ViewWrapper for BoxView {
wrap_impl!(content); wrap_impl_box!(self.content);
fn wrap_get_min_size(&self, _: SizeRequest) -> Vec2 { fn wrap_get_min_size(&self, _: SizeRequest) -> Vec2 {
self.size self.size

View File

@ -34,7 +34,7 @@ impl KeyEventView {
impl ViewWrapper for KeyEventView { impl ViewWrapper for KeyEventView {
wrap_impl!(content); wrap_impl_box!(self.content);
fn wrap_on_key_event(&mut self, ch: i32) -> EventResult { fn wrap_on_key_event(&mut self, ch: i32) -> EventResult {
match self.content.on_key_event(ch) { match self.content.on_key_event(ch) {

View File

@ -19,13 +19,7 @@ impl<T: View> SizedView<T> {
} }
impl <T: View> ViewWrapper for SizedView<T> { impl <T: View> ViewWrapper for SizedView<T> {
fn get_view(&self) -> &View { wrap_impl!(self.view);
&self.view
}
fn get_view_mut(&mut self) -> &mut View {
&mut self.view
}
fn wrap_layout(&mut self, size: Vec2) { fn wrap_layout(&mut self, size: Vec2) {
self.view.layout(size); self.view.layout(size);

View File

@ -44,7 +44,21 @@ impl <T: ViewWrapper> View for T {
#[macro_export] #[macro_export]
macro_rules! wrap_impl { macro_rules! wrap_impl {
($v:ident) => { (self.$v:ident) => {
fn get_view(&self) -> &View {
&self.$v
}
fn get_view_mut(&mut self) -> &mut View {
&mut self.$v
}
};
}
#[macro_export]
macro_rules! wrap_impl_box {
(self.$v:ident) => {
fn get_view(&self) -> &View { fn get_view(&self) -> &View {
&*self.$v &*self.$v