mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
move test crate into core
This commit is contained in:
parent
02db343574
commit
0a842b607a
12 changed files with 523 additions and 507 deletions
|
|
@ -388,20 +388,16 @@ impl<T> Align<T> {
|
|||
/// Enforce fixed size of drawing area
|
||||
pub enum Fixed<U: Number, T> {
|
||||
/// Enforce fixed width
|
||||
W(U, T),
|
||||
X(U, T),
|
||||
/// Enforce fixed height
|
||||
H(U, T),
|
||||
Y(U, T),
|
||||
/// Enforce fixed width and height
|
||||
WH(U, U, T),
|
||||
XY(U, U, T),
|
||||
}
|
||||
|
||||
impl<N: Number, T> Fixed<N, T> {
|
||||
pub fn inner (&self) -> &T {
|
||||
match self {
|
||||
Self::W(_, inner) => inner,
|
||||
Self::H(_, inner) => inner,
|
||||
Self::WH(_, _, inner) => inner,
|
||||
}
|
||||
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -415,7 +411,7 @@ pub enum Min<U: Number, T> {
|
|||
XY(U, U, T),
|
||||
}
|
||||
impl<N: Number, T> Min<N, T> {
|
||||
fn inner (&self) -> &T {
|
||||
pub fn inner (&self) -> &T {
|
||||
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
|
||||
}
|
||||
}
|
||||
|
|
@ -423,16 +419,12 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Min<E::Unit, T> {
|
|||
type Engine = E;
|
||||
fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
|
||||
Ok(match self {
|
||||
Self::X(w, _) => (to.w() < *w).then(||{
|
||||
[to.x() + *w, to.y(), to.w() - *w, to.h()]
|
||||
}),
|
||||
Self::Y(h, _) => (to.h() < *h).then(||{
|
||||
[to.x(), to.y() + *h, to.w(), to.h() - *h]
|
||||
}),
|
||||
Self::XY(w, h, _) => (to.w() < *w || to.h() < *h).then(||{
|
||||
[to.x() + *w, to.y() + *h, to.w() - *w, to.h() - *h]
|
||||
})
|
||||
}.map(|offset_area|self.inner().layout(offset_area.into())).transpose()?.flatten())
|
||||
Self::X(w, _) => (to.w() < *w).then(||[to.x() + *w, to.y(), to.w() - *w, to.h()]),
|
||||
Self::Y(h, _) => (to.h() < *h).then(||[to.x(), to.y() + *h, to.w(), to.h() - *h]),
|
||||
Self::XY(w, h, _) => (to.w() < *w || to.h() < *h).then(||[
|
||||
to.x() + *w, to.y() + *h, to.w() - *w, to.h() - *h
|
||||
])
|
||||
}.map(|stretched|self.inner().layout(stretched.into())).transpose()?.flatten())
|
||||
}
|
||||
// TODO: 🡘 🡙 ←🡙→
|
||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
||||
|
|
@ -458,18 +450,14 @@ impl<N: Number, T> Max<N, T> {
|
|||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Max<E:: Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
|
||||
Ok(match self {
|
||||
Self::X(w, _) => (area.w() < *w).then(||{
|
||||
[area.x(), area.y(), area.w().min(*w), area.h()]
|
||||
}),
|
||||
Self::Y(h, _) => (area.h() < *h).then(||{
|
||||
[area.x(), area.y(), area.w(), area.h().min(*h)]
|
||||
}),
|
||||
Self::XY(w, h, _) => (area.w() < *w || area.h() < *h).then(||{
|
||||
[area.x(), area.y(), area.w().min(*w), area.h().min(*h)]
|
||||
})
|
||||
}.map(|offset_area|self.inner().layout(offset_area.into())).transpose()?.flatten())
|
||||
Self::X(w, _) => (*w <= to.w()).then(||[to.x(), to.y(), to.w().min(*w), to.h()]),
|
||||
Self::Y(h, _) => (*h <= to.h()).then(||[to.x(), to.y(), to.w(), to.h().min(*h)]),
|
||||
Self::XY(w, h, _) => (*w <= to.w() || *h <= to.h()).then(||[
|
||||
to.x(), to.y(), to.w().min(*w), to.h().min(*h)
|
||||
])
|
||||
}.map(|clamped|self.inner().layout(clamped.into())).transpose()?.flatten())
|
||||
}
|
||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
||||
Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
|
||||
|
|
@ -494,18 +482,14 @@ impl<N: Number, T> Outset<N, T> {
|
|||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Outset<E::Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
|
||||
Ok(match self {
|
||||
Self::X(w, _) => (area.w() < *w).then(||{
|
||||
[area.x() - *w, area.y(), area.w() + *w + *w, area.h()]
|
||||
}),
|
||||
Self::Y(h, _) => (area.h() < *h).then(||{
|
||||
[area.x(), area.y() - *h, area.w(), area.h() + *h + *h]
|
||||
}),
|
||||
Self::XY(w, h, _) => (area.w() < *w || area.h() < *h).then(||{
|
||||
[area.x()- *w, area.y() - *h, area.w() + *w + *w, area.h() + *h + *h]
|
||||
})
|
||||
}.map(|offset_area|self.inner().layout(offset_area.into())).transpose()?.flatten())
|
||||
Self::X(w, _) => (*w <= to.w()).then(||[to.x() - *w, to.y(), to.w() + *w + *w, to.h()]),
|
||||
Self::Y(h, _) => (*h <= to.h()).then(||[to.x(), to.y() - *h, to.w(), to.h() + *h + *h]),
|
||||
Self::XY(w, h, _) => (*w <= to.w() || *h <= to.h()).then(||[
|
||||
to.x()- *w, to.y() - *h, to.w() + *w + *w, to.h() + *h + *h
|
||||
])
|
||||
}.map(|grown|self.inner().layout(grown.into())).transpose()?.flatten())
|
||||
}
|
||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
||||
Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
|
||||
|
|
@ -530,18 +514,14 @@ impl<N: Number, T: Widget> Inset<N, T> {
|
|||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Inset<E::Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
|
||||
Ok(match self {
|
||||
Self::X(w, _) => (area.w() < *w).then(||{
|
||||
[area.x() + *w, area.y(), area.w() - *w, area.h()]
|
||||
}),
|
||||
Self::Y(h, _) => (area.h() < *h).then(||{
|
||||
[area.x(), area.y() + *h, area.w(), area.h() - *h]
|
||||
}),
|
||||
Self::XY(w, h, _) => (area.w() < *w || area.h() < *h).then(||{
|
||||
[area.x() - *w, area.y() - *h, area.w() + *w, area.h() + *h]
|
||||
})
|
||||
}.map(|offset_area|self.inner().layout(offset_area.into())).transpose()?.flatten())
|
||||
Self::X(w, _) => (*w <= to.w()).then(||[to.x() + *w, to.y(), to.w() - *w, to.h()]),
|
||||
Self::Y(h, _) => (*h <= to.h()).then(||[to.x(), to.y() + *h, to.w(), to.h() - *h]),
|
||||
Self::XY(w, h, _) => (*w <= to.w() || *h <= to.h()).then(||[
|
||||
to.x() - *w, to.y() - *h, to.w() + *w, to.h() + *h
|
||||
])
|
||||
}.map(|shrunk|self.inner().layout(shrunk.into())).transpose()?.flatten())
|
||||
}
|
||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
||||
Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
|
||||
|
|
@ -562,22 +542,24 @@ impl<N: Number, T: Widget> Offset<N, T> {
|
|||
fn inner (&self) -> &T {
|
||||
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
|
||||
}
|
||||
fn x (&self) -> N {
|
||||
match self { Self::X(x, _) => *x, Self::Y(_, _) => N::default(), Self::XY(x, _, _) => *x }
|
||||
}
|
||||
fn y (&self) -> N {
|
||||
match self { Self::X(_, _) => N::default(), Self::Y(y, _) => *y, Self::XY(_, y, _) => *y }
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Offset<E::Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
|
||||
Ok(match self {
|
||||
Self::X(w, _) => (area.w() < *w).then(||{
|
||||
[area.x() + *w, area.y(), area.w() - *w, area.h()]
|
||||
}),
|
||||
Self::Y(h, _) => (area.h() < *h).then(||{
|
||||
[area.x(), area.y() + *h, area.w(), area.h() - *h]
|
||||
}),
|
||||
Self::XY(w, h, _) => (area.w() < *w || area.h() < *h).then(||{
|
||||
[area.x() + *w, area.y() + *h, area.w() - *w, area.h() - *h]
|
||||
})
|
||||
}.map(|offset_area|self.inner().layout(offset_area.into())).transpose()?.flatten())
|
||||
Self::X(w, _) => (*w <= to.w()).then(||[to.x() + *w, to.y(), to.w() - *w, to.h()]),
|
||||
Self::Y(h, _) => (*h <= to.h()).then(||[to.x(), to.y() + *h, to.w(), to.h() - *h]),
|
||||
Self::XY(w, h, _) => (*w <= to.w() || *h <= to.h()).then(||[
|
||||
to.x() + *w, to.y() + *h, to.w() - *w, to.h() - *h
|
||||
])
|
||||
}.map(|shifted|self.inner().layout(shifted.into())).transpose()?.flatten())
|
||||
}
|
||||
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
|
||||
Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue