move test crate into core

This commit is contained in:
🪞👃🪞 2024-09-12 22:31:51 +03:00
parent 02db343574
commit 0a842b607a
12 changed files with 523 additions and 507 deletions

View file

@ -454,18 +454,14 @@ pub const NOT_DIM_BOLD: Style = Style {
impl<T: Widget<Engine = Tui>> Widget for Fixed<u16, T> {
type Engine = Tui;
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
Ok(match self {
Self::W(w, item) => if area.w() < *w { None } else {
item.layout(area)?.map(|[x, y, _, h]|[x, y, *w, h])
},
Self::H(h, item) => if area.w() < *h { None } else {
item.layout(area)?.map(|[x, y, w, _]|[x, y, w, *h])
},
Self::WH(w, h, item) => if area.w() < *w || area.h() < *h { None } else {
item.layout(area)?.map(|[x, y, _, _]|[x, y, *w, *h])
}
})
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())
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
// 🡘 🡙 ←🡙→
@ -504,9 +500,8 @@ where
if w >= to.w() {
return Ok(())
}
if let Some([_, _, width, height]) = Offset::X(
w, component as &dyn Widget<Engine = Tui>
).layout(to)? {
let area = Offset::X(w, component as &dyn Widget<Engine = Tui>).layout(to)?;
if let Some([_, _, width, height]) = area {
w += width;
h = h.max(height)
}
@ -527,9 +522,8 @@ where
if h >= area.h() {
return Ok(())
}
if let Some([_, _, width, height]) = Offset::Y(
h, component as &dyn Widget<Engine = Tui>
).render(to)? {
let area = Offset::Y(h, component as &dyn Widget<Engine = Tui>).render(to)?;
if let Some([_, _, width, height]) = area {
h += height;
w = w.max(width)
};
@ -541,9 +535,8 @@ where
if w >= area.w() {
return Ok(())
}
if let Some([_, _, width, height]) = Offset::X(
w, component as &dyn Widget<Engine = Tui>
).render(to)? {
let area = Offset::X(w, component as &dyn Widget<Engine = Tui>).render(to)?;
if let Some([_, _, width, height]) = area {
w += width;
h = h.max(height)
};