chore: format

This commit is contained in:
same mf who else 2026-02-15 06:05:32 +02:00
parent 45e122668c
commit d5976cae8e

View file

@ -403,6 +403,7 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
push_pull!(Pull: minus);
layout_op_xy!(0: Fill);
impl<O: Out, T: Layout<O>> Layout<O> for Fill<T> {
fn x (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dx() { area.x() } else { self.inner().x(area) } }
fn y (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dy() { area.y() } else { self.inner().y(area) } }
@ -413,12 +414,14 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
fn h_min (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dy() { area.h() } else { self.inner().h_min(area) } }
fn h_max (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dy() { area.h() } else { self.inner().h_max(area) } }
}
impl<A> Fill<A> {
#[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<O: Out, T: Layout<O>> Layout<O> for Fixed<O::Unit, T> {
fn w (&self, area: XYWH<O::Unit>) -> O::Unit { self.dx().unwrap_or(self.inner().w(area)) }
fn w_min (&self, area: XYWH<O::Unit>) -> O::Unit { self.dx().unwrap_or(self.inner().w_min(area)) }
@ -429,6 +432,7 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
}
layout_op_xy!(1 opt: Max);
impl<E: Out, T: Layout<E>> Layout<E> for Max<E::Unit, T> {
fn layout (&self, area: XYWH<E::Unit>) -> XYWH<E::Unit> {
let XYWH(x, y, w, h) = self.inner().layout(area);
@ -441,6 +445,7 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
}
layout_op_xy!(1 opt: Min);
impl<E: Out, T: Layout<E>> Layout<E> for Min<E::Unit, T> {
fn layout (&self, area: XYWH<E::Unit>) -> XYWH<E::Unit> {
let XYWH(x, y, w, h) = self.inner().layout(area);
@ -453,6 +458,7 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
}
layout_op_xy!(1 opt: Expand);
impl<O: Out, T: Layout<O>> Layout<O> for Expand<O::Unit, T> {
fn w (&self, to: XYWH<O::Unit>) -> O::Unit {
self.inner().w(to).plus(self.dx().unwrap_or_default())
@ -465,6 +471,7 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
// FIXME: why they differ?
layout_op_xy!(1 opt: Shrink);
impl<E: Out, T: Layout<E>> Layout<E> for Shrink<E::Unit, T> {
fn layout (&self, to: XYWH<E::Unit>) -> XYWH<E::Unit> {
let area = self.inner().layout(to);
@ -517,6 +524,7 @@ impl<U, A> Pad<U, A> {
match self { X(_, c) | Y(_, c) | XY(_, _, c) => c, }
}
}
impl<U: Coord, T> Pad<U, T> {
#[inline] pub fn dx (&self) -> U {
use Pad::*;
@ -527,15 +535,18 @@ impl<U: Coord, T> Pad<U, T> {
match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, }
}
}
impl<O: Out, T: Content<O>> Draw<O> for Pad<O::Unit, T> {
fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) }
}
impl<O: Out, T: Layout<O>> Layout<O> for Pad<O::Unit, T> {
fn x (&self, area: XYWH<O::Unit>) -> O::Unit { area.x().plus(self.dx()) }
fn y (&self, area: XYWH<O::Unit>) -> O::Unit { area.x().plus(self.dx()) }
fn w (&self, area: XYWH<O::Unit>) -> O::Unit { area.w().minus(self.dx() * 2.into()) }
fn h (&self, area: XYWH<O::Unit>) -> O::Unit { area.h().minus(self.dy() * 2.into()) }
}
impl<Head, Tail> Bsp<Head, Tail> {
#[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<O: Out, Head: Content<O>, Tail: Content<O>> Draw<O> for Bsp<Head, Tail> {
//}
}
}
impl<O: Out, Head: Layout<O>, Tail: Layout<O>> Layout<O> for Bsp<Head, Tail> {
fn w (&self, area: XYWH<O::Unit>) -> 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<O> for Map<O, A, B, I, F, G> where
area.centered_xy([w.into(), h.into()])
}
}
impl<'a, O, A, B, I, F, G> Draw<O> for Map<O, A, B, I, F, G> where
O: Out,
B: Content<O>,
@ -786,11 +799,13 @@ impl<O: Out, T, L: Content<O>, V: Content<O>> Layout<O> for FieldV<T, L, V> {
impl<O: Out, T, L: Content<O>, V: Content<O>> Draw<O> for FieldV<T, L, V> {
fn draw (&self, to: &mut O) { self.content().draw(to) }
}
impl<O: Out, S: Layout<O>> Layout<O> for Border<S> {
fn layout (&self, area: XYWH<O::Unit>) -> XYWH<O::Unit> {
self.1.layout(area)
}
}
impl<C, T, U> Field<C, T, U> {
pub fn new (direction: Direction) -> Field<C, (), ()> {
Field::<C, (), ()> {