use crate::*; /// Defines an enum that transforms its content /// along either the X axis, the Y axis, or both. /// /// The `_Unused` variant wraps the `Output` type /// using `PhantomData` to permit the double generic. macro_rules! transform_xy { ($self:ident : $Enum:ident |$to:ident|$area:expr) => { pub enum $Enum { X(T), Y(T), XY(T) } impl $Enum { pub fn x (item: T) -> Self { Self::X(item) } pub fn y (item: T) -> Self { Self::Y(item) } pub fn xy (item: T) -> Self { Self::XY(item) } } impl> Content for $Enum { fn content (&self) -> impl Render { match self { Self::X(item) => item, Self::Y(item) => item, Self::XY(item) => item } } fn layout (&$self, $to: ::Area) -> ::Area { use $Enum::*; $area } } } } transform_xy!(self: Fill |to|{ let [x0, y0, wmax, hmax] = to.xywh(); let [x, y, w, h] = self.content().layout(to).xywh(); match self { X(_) => [x0, y, wmax, h], Y(_) => [x, y0, w, hmax], XY(_) => [x0, y0, wmax, hmax], }.into() });