From d5976cae8e858f717ff051602f7d8570d6eab30d Mon Sep 17 00:00:00 2001 From: same mf who else Date: Sun, 15 Feb 2026 06:05:32 +0200 Subject: [PATCH] chore: format --- output/src/out_impls.rs | 141 ++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 63 deletions(-) diff --git a/output/src/out_impls.rs b/output/src/out_impls.rs index 34b9f47..956630f 100644 --- a/output/src/out_impls.rs +++ b/output/src/out_impls.rs @@ -398,81 +398,88 @@ impl, B: Content> Draw for Either { } } - push_pull!(Push: plus); +push_pull!(Push: plus); - push_pull!(Pull: minus); +push_pull!(Pull: minus); - layout_op_xy!(0: Fill); - impl> Layout for Fill { - fn x (&self, area: XYWH) -> O::Unit { if self.dx() { area.x() } else { self.inner().x(area) } } - fn y (&self, area: XYWH) -> O::Unit { if self.dy() { area.y() } else { self.inner().y(area) } } - fn w (&self, area: XYWH) -> O::Unit { if self.dx() { area.w() } else { self.inner().w(area) } } - fn w_min (&self, area: XYWH) -> O::Unit { if self.dx() { area.w() } else { self.inner().w_min(area) } } - fn w_max (&self, area: XYWH) -> O::Unit { if self.dx() { area.w() } else { self.inner().w_max(area) } } - fn h (&self, area: XYWH) -> O::Unit { if self.dy() { area.h() } else { self.inner().h(area) } } - fn h_min (&self, area: XYWH) -> O::Unit { if self.dy() { area.h() } else { self.inner().h_min(area) } } - fn h_max (&self, area: XYWH) -> O::Unit { if self.dy() { area.h() } else { self.inner().h_max(area) } } - } - impl Fill { - #[inline] pub const fn dx (&self) -> bool { matches!(self, Self::X(_) | Self::XY(_)) } - #[inline] pub const fn dy (&self) -> bool { matches!(self, Self::Y(_) | Self::XY(_)) } - } +layout_op_xy!(0: Fill); - layout_op_xy!(1 opt: Fixed); - impl> Layout for Fixed { - fn w (&self, area: XYWH) -> O::Unit { self.dx().unwrap_or(self.inner().w(area)) } - fn w_min (&self, area: XYWH) -> O::Unit { self.dx().unwrap_or(self.inner().w_min(area)) } - fn w_max (&self, area: XYWH) -> O::Unit { self.dx().unwrap_or(self.inner().w_max(area)) } - fn h (&self, area: XYWH) -> O::Unit { self.dy().unwrap_or(self.inner().h(area)) } - fn h_min (&self, area: XYWH) -> O::Unit { self.dy().unwrap_or(self.inner().h_min(area)) } - fn h_max (&self, area: XYWH) -> O::Unit { self.dy().unwrap_or(self.inner().h_max(area)) } - } +impl> Layout for Fill { + fn x (&self, area: XYWH) -> O::Unit { if self.dx() { area.x() } else { self.inner().x(area) } } + fn y (&self, area: XYWH) -> O::Unit { if self.dy() { area.y() } else { self.inner().y(area) } } + fn w (&self, area: XYWH) -> O::Unit { if self.dx() { area.w() } else { self.inner().w(area) } } + fn w_min (&self, area: XYWH) -> O::Unit { if self.dx() { area.w() } else { self.inner().w_min(area) } } + fn w_max (&self, area: XYWH) -> O::Unit { if self.dx() { area.w() } else { self.inner().w_max(area) } } + fn h (&self, area: XYWH) -> O::Unit { if self.dy() { area.h() } else { self.inner().h(area) } } + fn h_min (&self, area: XYWH) -> O::Unit { if self.dy() { area.h() } else { self.inner().h_min(area) } } + fn h_max (&self, area: XYWH) -> O::Unit { if self.dy() { area.h() } else { self.inner().h_max(area) } } +} - layout_op_xy!(1 opt: Max); - impl> Layout for Max { - fn layout (&self, area: XYWH) -> XYWH { - let XYWH(x, y, w, h) = self.inner().layout(area); - match self { - Self::X(mw, _) => XYWH(x, y, w.min(*mw), h ), - Self::Y(mh, _) => XYWH(x, y, w, h.min(*mh)), - Self::XY(mw, mh, _) => XYWH(x, y, w.min(*mw), h.min(*mh)), - } +impl Fill { + #[inline] pub const fn dx (&self) -> bool { matches!(self, Self::X(_) | Self::XY(_)) } + #[inline] pub const fn dy (&self) -> bool { matches!(self, Self::Y(_) | Self::XY(_)) } +} + +layout_op_xy!(1 opt: Fixed); + +impl> Layout for Fixed { + fn w (&self, area: XYWH) -> O::Unit { self.dx().unwrap_or(self.inner().w(area)) } + fn w_min (&self, area: XYWH) -> O::Unit { self.dx().unwrap_or(self.inner().w_min(area)) } + fn w_max (&self, area: XYWH) -> O::Unit { self.dx().unwrap_or(self.inner().w_max(area)) } + fn h (&self, area: XYWH) -> O::Unit { self.dy().unwrap_or(self.inner().h(area)) } + fn h_min (&self, area: XYWH) -> O::Unit { self.dy().unwrap_or(self.inner().h_min(area)) } + fn h_max (&self, area: XYWH) -> O::Unit { self.dy().unwrap_or(self.inner().h_max(area)) } +} + +layout_op_xy!(1 opt: Max); + +impl> Layout for Max { + fn layout (&self, area: XYWH) -> XYWH { + let XYWH(x, y, w, h) = self.inner().layout(area); + match self { + Self::X(mw, _) => XYWH(x, y, w.min(*mw), h ), + Self::Y(mh, _) => XYWH(x, y, w, h.min(*mh)), + Self::XY(mw, mh, _) => XYWH(x, y, w.min(*mw), h.min(*mh)), } } +} - layout_op_xy!(1 opt: Min); - impl> Layout for Min { - fn layout (&self, area: XYWH) -> XYWH { - let XYWH(x, y, w, h) = self.inner().layout(area); - match self { - Self::X(mw, _) => XYWH(x, y, w.max(*mw), h), - Self::Y(mh, _) => XYWH(x, y, w, h.max(*mh)), - Self::XY(mw, mh, _) => XYWH(x, y, w.max(*mw), h.max(*mh)), - } +layout_op_xy!(1 opt: Min); + +impl> Layout for Min { + fn layout (&self, area: XYWH) -> XYWH { + let XYWH(x, y, w, h) = self.inner().layout(area); + match self { + Self::X(mw, _) => XYWH(x, y, w.max(*mw), h), + Self::Y(mh, _) => XYWH(x, y, w, h.max(*mh)), + Self::XY(mw, mh, _) => XYWH(x, y, w.max(*mw), h.max(*mh)), } } +} - layout_op_xy!(1 opt: Expand); - impl> Layout for Expand { - fn w (&self, to: XYWH) -> O::Unit { - self.inner().w(to).plus(self.dx().unwrap_or_default()) - } - fn h (&self, to: XYWH) -> O::Unit { - self.inner().w(to).plus(self.dy().unwrap_or_default()) - } +layout_op_xy!(1 opt: Expand); + +impl> Layout for Expand { + fn w (&self, to: XYWH) -> O::Unit { + self.inner().w(to).plus(self.dx().unwrap_or_default()) } - - // FIXME: why they differ? - - layout_op_xy!(1 opt: Shrink); - impl> Layout for Shrink { - fn layout (&self, to: XYWH) -> XYWH { - let area = self.inner().layout(to); - let dx = self.dx().unwrap_or_default(); - let dy = self.dy().unwrap_or_default(); - XYWH(area.x(), area.y(), area.w().minus(dx), area.h().minus(dy)) - } + fn h (&self, to: XYWH) -> O::Unit { + self.inner().w(to).plus(self.dy().unwrap_or_default()) } +} + +// FIXME: why they differ? + +layout_op_xy!(1 opt: Shrink); + +impl> Layout for Shrink { + fn layout (&self, to: XYWH) -> XYWH { + let area = self.inner().layout(to); + let dx = self.dx().unwrap_or_default(); + let dy = self.dy().unwrap_or_default(); + XYWH(area.x(), area.y(), area.w().minus(dx), area.h().minus(dy)) + } +} impl Align { #[inline] pub const fn c (a: T) -> Self { Self(Alignment::Center, a) } @@ -517,6 +524,7 @@ impl Pad { match self { X(_, c) | Y(_, c) | XY(_, _, c) => c, } } } + impl Pad { #[inline] pub fn dx (&self) -> U { use Pad::*; @@ -527,15 +535,18 @@ impl Pad { match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, } } } + impl> Draw for Pad { fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } + impl> Layout for Pad { fn x (&self, area: XYWH) -> O::Unit { area.x().plus(self.dx()) } fn y (&self, area: XYWH) -> O::Unit { area.x().plus(self.dx()) } fn w (&self, area: XYWH) -> O::Unit { area.w().minus(self.dx() * 2.into()) } fn h (&self, area: XYWH) -> O::Unit { area.h().minus(self.dy() * 2.into()) } } + impl Bsp { #[inline] pub const fn n (a: Head, b: Tail) -> Self { Self(North, a, b) } #[inline] pub const fn s (a: Head, b: Tail) -> Self { Self(South, a, b) } @@ -572,6 +583,7 @@ impl, Tail: Content> Draw for Bsp { //} } } + impl, Tail: Layout> Layout for Bsp { fn w (&self, area: XYWH) -> O::Unit { match self.0 { Above | Below | North | South => self.1.w(area).max(self.2.w(area)), East | West => self.1.w_min(area).plus(self.2.w(area)), } @@ -690,6 +702,7 @@ impl<'a, O, A, B, I, F, G> Layout for Map where area.centered_xy([w.into(), h.into()]) } } + impl<'a, O, A, B, I, F, G> Draw for Map where O: Out, B: Content, @@ -786,11 +799,13 @@ impl, V: Content> Layout for FieldV { impl, V: Content> Draw for FieldV { fn draw (&self, to: &mut O) { self.content().draw(to) } } + impl> Layout for Border { fn layout (&self, area: XYWH) -> XYWH { self.1.layout(area) } } + impl Field { pub fn new (direction: Direction) -> Field { Field:: {