diff --git a/src/view/mod.rs b/src/view/mod.rs index 5dedd28..09f7692 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -1,6 +1,7 @@ //! Defines various views to use when creating the layout. -#[macro_use]mod view_wrapper; +#[macro_use] +mod view_wrapper; // Essentials components mod position; @@ -24,6 +25,7 @@ mod select_view; mod sized_view; mod stack_view; mod text_view; +mod tracked_view; use std::any::Any; @@ -50,6 +52,7 @@ pub use self::select_view::SelectView; pub use self::shadow_view::ShadowView; pub use self::stack_view::StackView; pub use self::text_view::TextView; +pub use self::tracked_view::TrackedView; pub use self::sized_view::SizedView; pub use self::view_wrapper::ViewWrapper; diff --git a/src/view/position.rs b/src/view/position.rs index 4e724f7..401781f 100644 --- a/src/view/position.rs +++ b/src/view/position.rs @@ -1,4 +1,4 @@ -use ::vec::{ToVec2, Vec2}; +use vec::{ToVec2, Vec2}; /// Location of the view on screen pub struct Position { @@ -8,10 +8,7 @@ pub struct Position { impl Position { pub fn new(x: Offset, y: Offset) -> Self { - Position { - x: x, - y: y, - } + Position { x: x, y: y } } pub fn center() -> Self { diff --git a/src/view/sized_view.rs b/src/view/sized_view.rs index 52fe27e..ad258e6 100644 --- a/src/view/sized_view.rs +++ b/src/view/sized_view.rs @@ -24,7 +24,7 @@ impl ViewWrapper for SizedView { wrap_impl!(&self.view); fn wrap_layout(&mut self, size: Vec2) { - self.view.layout(size); self.size = size; + self.view.layout(size); } } diff --git a/src/view/tracked_view.rs b/src/view/tracked_view.rs new file mode 100644 index 0000000..6542228 --- /dev/null +++ b/src/view/tracked_view.rs @@ -0,0 +1,30 @@ +use view::{IdView, View, ViewWrapper}; +use printer::Printer; +use vec::Vec2; + +pub struct TrackedView { + pub view: T, + pub offset: Vec2, +} + +impl TrackedView { + pub fn new(view: T) -> Self { + TrackedView { + view: view, + offset: Vec2::zero(), + } + } + + pub fn with_id(self, id: &str) -> IdView { + IdView::new(id, self) + } +} + +impl ViewWrapper for TrackedView { + wrap_impl!(&self.view); + + fn wrap_draw(&mut self, printer: &Printer) { + self.offset = printer.offset; + self.view.draw(printer); + } +}