From c597c262fe53fe482a201b8944025d680cf361a4 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 11 Jul 2016 19:35:18 -0700 Subject: [PATCH] Add single-orientation FullView full_width and full_height --- src/view/full_view.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/view/full_view.rs b/src/view/full_view.rs index 113fcce..ffb0a28 100644 --- a/src/view/full_view.rs +++ b/src/view/full_view.rs @@ -1,22 +1,54 @@ use view::{View, ViewWrapper}; +use orientation::Orientation; use vec::Vec2; /// Simple wrapper view that asks for all the space it can get. pub struct FullView { view: T, + orientation: Option, +} + +#[derive(Debug, PartialEq)] +enum Type { + FullWidth, + FullHeight, + FullScreen, } impl FullView { /// Wraps the given view into a new FullView. pub fn new(view: T) -> Self { - FullView { view: view } + FullView { + view: view, + orientation: None, + } + } + + pub fn full_width(view: T) -> Self { + FullView { + view: view, + orientation: Some(Orientation::Horizontal), + } + } + + pub fn full_height(view: T) -> Self { + FullView { + view: view, + orientation: Some(Orientation::Vertical), + } } } impl ViewWrapper for FullView { wrap_impl!(&self.view); - fn wrap_get_min_size(&mut self, req: Vec2) -> Vec2 { + fn wrap_get_min_size(&mut self, mut req: Vec2) -> Vec2 { + if let Some(orientation) = self.orientation { + let child_size = self.view.get_min_size(req); + let orientation = orientation.swap(); + *orientation.get_ref(&mut req) = orientation.get(&child_size); + } + req } }