diff --git a/src/layout/axis.rs b/src/layout/axis.rs index ff66ffc..1178b69 100644 --- a/src/layout/axis.rs +++ b/src/layout/axis.rs @@ -8,6 +8,14 @@ pub enum Exact<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X), } +pub enum Shrink<'a, S: Screen, I: Draw, X: Into>> { + __(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X), +} + +pub enum Expand<'a, S: Screen, I: Draw, X: Into>> { + __(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X), +} + pub enum Push<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X), } @@ -375,6 +383,34 @@ impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Ma } } +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Expand<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { + #[cfg(feature = "prof")] profiling::scope!("expand_draw"); + let XYWH(x, y, w0, h0) = to.area(); + let (item, w, h) = match self { + Self::W(item, w) => (item, (*w).into(), None), + Self::H(item, h) => (item, None, (*h).into()), + Self::WH(item, w, h) => (item, (*w).into(), (*h).into()), + _ => return Ok(None) + }; + to.draw(XYWH(x, y, w0 + w.unwrap_or_default(), h0 + h.unwrap_or_default()), item) + } +} + +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Shrink<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { + #[cfg(feature = "prof")] profiling::scope!("shrink_draw"); + let XYWH(x, y, w0, h0) = to.area(); + let (item, w, h) = match self { + Self::W(item, w) => (item, (*w).into(), None), + Self::H(item, h) => (item, None, (*h).into()), + Self::WH(item, w, h) => (item, (*w).into(), (*h).into()), + _ => return Ok(None) + }; + to.draw(XYWH(x, y, w0.minus(w.unwrap_or_default()), h0.minus(h.unwrap_or_default())), item) + } +} + impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Push<'a, S, I, X> { fn draw (&self, to: &mut S) -> Drawn { #[cfg(feature = "prof")] profiling::scope!("push_draw");