mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 10:39:03 +01:00
chore: format
This commit is contained in:
parent
45e122668c
commit
d5976cae8e
1 changed files with 78 additions and 63 deletions
|
|
@ -398,12 +398,13 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push_pull!(Push: plus);
|
push_pull!(Push: plus);
|
||||||
|
|
||||||
push_pull!(Pull: minus);
|
push_pull!(Pull: minus);
|
||||||
|
|
||||||
layout_op_xy!(0: Fill);
|
layout_op_xy!(0: Fill);
|
||||||
impl<O: Out, T: Layout<O>> Layout<O> for Fill<T> {
|
|
||||||
|
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 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) } }
|
fn y (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dy() { area.y() } else { self.inner().y(area) } }
|
||||||
fn w (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dx() { area.w() } else { self.inner().w(area) } }
|
fn w (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dx() { area.w() } else { self.inner().w(area) } }
|
||||||
|
|
@ -412,24 +413,27 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
|
||||||
fn h (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dy() { area.h() } else { self.inner().h(area) } }
|
fn h (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dy() { area.h() } else { self.inner().h(area) } }
|
||||||
fn h_min (&self, area: XYWH<O::Unit>) -> O::Unit { if self.dy() { area.h() } else { self.inner().h_min(area) } }
|
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) } }
|
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> {
|
|
||||||
|
impl<A> Fill<A> {
|
||||||
#[inline] pub const fn dx (&self) -> bool { matches!(self, Self::X(_) | Self::XY(_)) }
|
#[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(_)) }
|
#[inline] pub const fn dy (&self) -> bool { matches!(self, Self::Y(_) | Self::XY(_)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_op_xy!(1 opt: Fixed);
|
layout_op_xy!(1 opt: Fixed);
|
||||||
impl<O: Out, T: Layout<O>> Layout<O> for Fixed<O::Unit, T> {
|
|
||||||
|
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 (&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)) }
|
fn w_min (&self, area: XYWH<O::Unit>) -> O::Unit { self.dx().unwrap_or(self.inner().w_min(area)) }
|
||||||
fn w_max (&self, area: XYWH<O::Unit>) -> O::Unit { self.dx().unwrap_or(self.inner().w_max(area)) }
|
fn w_max (&self, area: XYWH<O::Unit>) -> O::Unit { self.dx().unwrap_or(self.inner().w_max(area)) }
|
||||||
fn h (&self, area: XYWH<O::Unit>) -> O::Unit { self.dy().unwrap_or(self.inner().h(area)) }
|
fn h (&self, area: XYWH<O::Unit>) -> O::Unit { self.dy().unwrap_or(self.inner().h(area)) }
|
||||||
fn h_min (&self, area: XYWH<O::Unit>) -> O::Unit { self.dy().unwrap_or(self.inner().h_min(area)) }
|
fn h_min (&self, area: XYWH<O::Unit>) -> O::Unit { self.dy().unwrap_or(self.inner().h_min(area)) }
|
||||||
fn h_max (&self, area: XYWH<O::Unit>) -> O::Unit { self.dy().unwrap_or(self.inner().h_max(area)) }
|
fn h_max (&self, area: XYWH<O::Unit>) -> O::Unit { self.dy().unwrap_or(self.inner().h_max(area)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_op_xy!(1 opt: Max);
|
layout_op_xy!(1 opt: Max);
|
||||||
impl<E: Out, T: Layout<E>> Layout<E> for Max<E::Unit, T> {
|
|
||||||
|
impl<E: Out, T: Layout<E>> Layout<E> for Max<E::Unit, T> {
|
||||||
fn layout (&self, area: XYWH<E::Unit>) -> XYWH<E::Unit> {
|
fn layout (&self, area: XYWH<E::Unit>) -> XYWH<E::Unit> {
|
||||||
let XYWH(x, y, w, h) = self.inner().layout(area);
|
let XYWH(x, y, w, h) = self.inner().layout(area);
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -438,10 +442,11 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
|
||||||
Self::XY(mw, mh, _) => XYWH(x, y, w.min(*mw), h.min(*mh)),
|
Self::XY(mw, mh, _) => XYWH(x, y, w.min(*mw), h.min(*mh)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_op_xy!(1 opt: Min);
|
layout_op_xy!(1 opt: Min);
|
||||||
impl<E: Out, T: Layout<E>> Layout<E> for Min<E::Unit, T> {
|
|
||||||
|
impl<E: Out, T: Layout<E>> Layout<E> for Min<E::Unit, T> {
|
||||||
fn layout (&self, area: XYWH<E::Unit>) -> XYWH<E::Unit> {
|
fn layout (&self, area: XYWH<E::Unit>) -> XYWH<E::Unit> {
|
||||||
let XYWH(x, y, w, h) = self.inner().layout(area);
|
let XYWH(x, y, w, h) = self.inner().layout(area);
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -450,29 +455,31 @@ impl<E: Out, A: Content<E>, B: Content<E>> Draw<E> for Either<E, A, B> {
|
||||||
Self::XY(mw, mh, _) => XYWH(x, y, w.max(*mw), h.max(*mh)),
|
Self::XY(mw, mh, _) => XYWH(x, y, w.max(*mw), h.max(*mh)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_op_xy!(1 opt: Expand);
|
layout_op_xy!(1 opt: Expand);
|
||||||
impl<O: Out, T: Layout<O>> Layout<O> for Expand<O::Unit, T> {
|
|
||||||
|
impl<O: Out, T: Layout<O>> Layout<O> for Expand<O::Unit, T> {
|
||||||
fn w (&self, to: XYWH<O::Unit>) -> O::Unit {
|
fn w (&self, to: XYWH<O::Unit>) -> O::Unit {
|
||||||
self.inner().w(to).plus(self.dx().unwrap_or_default())
|
self.inner().w(to).plus(self.dx().unwrap_or_default())
|
||||||
}
|
}
|
||||||
fn h (&self, to: XYWH<O::Unit>) -> O::Unit {
|
fn h (&self, to: XYWH<O::Unit>) -> O::Unit {
|
||||||
self.inner().w(to).plus(self.dy().unwrap_or_default())
|
self.inner().w(to).plus(self.dy().unwrap_or_default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: why they differ?
|
// FIXME: why they differ?
|
||||||
|
|
||||||
layout_op_xy!(1 opt: Shrink);
|
layout_op_xy!(1 opt: Shrink);
|
||||||
impl<E: Out, T: Layout<E>> Layout<E> for Shrink<E::Unit, T> {
|
|
||||||
|
impl<E: Out, T: Layout<E>> Layout<E> for Shrink<E::Unit, T> {
|
||||||
fn layout (&self, to: XYWH<E::Unit>) -> XYWH<E::Unit> {
|
fn layout (&self, to: XYWH<E::Unit>) -> XYWH<E::Unit> {
|
||||||
let area = self.inner().layout(to);
|
let area = self.inner().layout(to);
|
||||||
let dx = self.dx().unwrap_or_default();
|
let dx = self.dx().unwrap_or_default();
|
||||||
let dy = self.dy().unwrap_or_default();
|
let dy = self.dy().unwrap_or_default();
|
||||||
XYWH(area.x(), area.y(), area.w().minus(dx), area.h().minus(dy))
|
XYWH(area.x(), area.y(), area.w().minus(dx), area.h().minus(dy))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Align<T> {
|
impl<T> Align<T> {
|
||||||
#[inline] pub const fn c (a: T) -> Self { Self(Alignment::Center, a) }
|
#[inline] pub const fn c (a: T) -> Self { Self(Alignment::Center, a) }
|
||||||
|
|
@ -517,6 +524,7 @@ impl<U, A> Pad<U, A> {
|
||||||
match self { X(_, c) | Y(_, c) | XY(_, _, c) => c, }
|
match self { X(_, c) | Y(_, c) | XY(_, _, c) => c, }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: Coord, T> Pad<U, T> {
|
impl<U: Coord, T> Pad<U, T> {
|
||||||
#[inline] pub fn dx (&self) -> U {
|
#[inline] pub fn dx (&self) -> U {
|
||||||
use Pad::*;
|
use Pad::*;
|
||||||
|
|
@ -527,15 +535,18 @@ impl<U: Coord, T> Pad<U, T> {
|
||||||
match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, }
|
match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<O: Out, T: Content<O>> Draw<O> for Pad<O::Unit, T> {
|
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) }
|
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> {
|
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 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 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 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()) }
|
fn h (&self, area: XYWH<O::Unit>) -> O::Unit { area.h().minus(self.dy() * 2.into()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Head, Tail> Bsp<Head, Tail> {
|
impl<Head, Tail> Bsp<Head, Tail> {
|
||||||
#[inline] pub const fn n (a: Head, b: Tail) -> Self { Self(North, a, b) }
|
#[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) }
|
#[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> {
|
impl<O: Out, Head: Layout<O>, Tail: Layout<O>> Layout<O> for Bsp<Head, Tail> {
|
||||||
fn w (&self, area: XYWH<O::Unit>) -> O::Unit {
|
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)), }
|
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()])
|
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
|
impl<'a, O, A, B, I, F, G> Draw<O> for Map<O, A, B, I, F, G> where
|
||||||
O: Out,
|
O: Out,
|
||||||
B: Content<O>,
|
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> {
|
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) }
|
fn draw (&self, to: &mut O) { self.content().draw(to) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<O: Out, S: Layout<O>> Layout<O> for Border<S> {
|
impl<O: Out, S: Layout<O>> Layout<O> for Border<S> {
|
||||||
fn layout (&self, area: XYWH<O::Unit>) -> XYWH<O::Unit> {
|
fn layout (&self, area: XYWH<O::Unit>) -> XYWH<O::Unit> {
|
||||||
self.1.layout(area)
|
self.1.layout(area)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, T, U> Field<C, T, U> {
|
impl<C, T, U> Field<C, T, U> {
|
||||||
pub fn new (direction: Direction) -> Field<C, (), ()> {
|
pub fn new (direction: Direction) -> Field<C, (), ()> {
|
||||||
Field::<C, (), ()> {
|
Field::<C, (), ()> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue