From 191c2899ea2abd22e265022c8867cb2f199d48d0 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 19 May 2015 16:40:32 -0700 Subject: [PATCH] Add non-boxed wrap_impl! macro Although maybe sized_view should rather use a box internally. --- src/view/box_view.rs | 2 +- src/view/key_event_view.rs | 2 +- src/view/sized_view.rs | 8 +------- src/view/view_wrapper.rs | 16 +++++++++++++++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/view/box_view.rs b/src/view/box_view.rs index 239e248..0dc2540 100644 --- a/src/view/box_view.rs +++ b/src/view/box_view.rs @@ -27,7 +27,7 @@ impl BoxView { impl ViewWrapper for BoxView { - wrap_impl!(content); + wrap_impl_box!(self.content); fn wrap_get_min_size(&self, _: SizeRequest) -> Vec2 { self.size diff --git a/src/view/key_event_view.rs b/src/view/key_event_view.rs index 87181a6..cf5fa4e 100644 --- a/src/view/key_event_view.rs +++ b/src/view/key_event_view.rs @@ -34,7 +34,7 @@ impl KeyEventView { impl ViewWrapper for KeyEventView { - wrap_impl!(content); + wrap_impl_box!(self.content); fn wrap_on_key_event(&mut self, ch: i32) -> EventResult { match self.content.on_key_event(ch) { diff --git a/src/view/sized_view.rs b/src/view/sized_view.rs index a62a978..6fd8fa4 100644 --- a/src/view/sized_view.rs +++ b/src/view/sized_view.rs @@ -19,13 +19,7 @@ impl SizedView { } impl ViewWrapper for SizedView { - fn get_view(&self) -> &View { - &self.view - } - - fn get_view_mut(&mut self) -> &mut View { - &mut self.view - } + wrap_impl!(self.view); fn wrap_layout(&mut self, size: Vec2) { self.view.layout(size); diff --git a/src/view/view_wrapper.rs b/src/view/view_wrapper.rs index bb1d019..cad32a5 100644 --- a/src/view/view_wrapper.rs +++ b/src/view/view_wrapper.rs @@ -44,7 +44,21 @@ impl View for T { #[macro_export] 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 { &*self.$v