mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
fix Fixed
This commit is contained in:
parent
01dacd407d
commit
8c28ef2bd7
4 changed files with 31 additions and 29 deletions
|
|
@ -13,18 +13,18 @@ pub(crate) use std::marker::PhantomData;
|
|||
|
||||
#[cfg(test)] #[test] fn test_layout () -> Usually<()> {
|
||||
use crate::tui::Tui;
|
||||
|
||||
let area: [u16;4] = [10, 10, 20, 20];
|
||||
let unit = ();
|
||||
|
||||
assert_eq!(Content::<Tui>::layout(&unit, area), [20, 20, 0, 0]);
|
||||
|
||||
assert_eq!(Fill::<Tui, _>::x(unit).layout(area), [10, 20, 20, 0]);
|
||||
assert_eq!(Fill::<Tui, _>::y(unit).layout(area), [20, 10, 0, 20]);
|
||||
assert_eq!(Fill::<Tui, _>::xy(unit).layout(area), area);
|
||||
|
||||
assert_eq!(Align::<Tui, _>::c(unit).layout(area), [20, 20, 0, 0]);
|
||||
assert_eq!(Align::<Tui, _>::c(" ").layout(area), [20, 20, 0, 0]);
|
||||
|
||||
assert_eq!(Content::<Tui>::layout(&(), area),
|
||||
[20, 20, 0, 0]);
|
||||
assert_eq!(Fill::<Tui, _>::x(()).layout(area),
|
||||
[10, 20, 20, 0]);
|
||||
assert_eq!(Fill::<Tui, _>::y(()).layout(area),
|
||||
[20, 10, 0, 20]);
|
||||
assert_eq!(Fill::<Tui, _>::xy(()).layout(area),
|
||||
area);
|
||||
assert_eq!(Fixed::<Tui, _>::xy(4, 4, ()).layout(area),
|
||||
[18, 18, 4, 4]);
|
||||
assert_eq!(Align::<Tui, _>::c(()).layout(area),
|
||||
[20, 20, 0, 0]);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,23 +42,25 @@ macro_rules! transform_xy_unit {
|
|||
}
|
||||
|
||||
transform_xy_unit!(|self: Fixed, area|{
|
||||
let area = self.content().layout(area);
|
||||
let [x, y, w, h] = self.content().layout(area.center_xy(match self {
|
||||
Self::X(fw, _) => [*fw, area.h()],
|
||||
Self::Y(fh, _) => [area.w(), *fh],
|
||||
Self::XY(fw, fh, _) => [*fw, *fh],
|
||||
}).into()).xywh();
|
||||
match self {
|
||||
Self::X(fw, _) => [area.x(), area.y(), *fw, area.h()],
|
||||
Self::Y(fh, _) => [area.x(), area.y(), area.w(), *fh],
|
||||
Self::XY(fw, fh, _) => [area.x(), area.y(), *fw, *fh], // tagn
|
||||
Self::X(fw, _) => [x, y, *fw, h],
|
||||
Self::Y(fh, _) => [x, y, w, *fh],
|
||||
Self::XY(fw, fh, _) => [x, y, *fw, *fh],
|
||||
}
|
||||
});
|
||||
|
||||
transform_xy_unit!(|self: Shrink, area|{
|
||||
let area = self.content().layout(area);
|
||||
[area.x(), area.y(), area.w().minus(self.dx()), area.h().minus(self.dy())]
|
||||
});
|
||||
transform_xy_unit!(|self: Shrink, area|self.content().layout([
|
||||
area.x(), area.y(), area.w().minus(self.dx()), area.h().minus(self.dy())
|
||||
].into()));
|
||||
|
||||
transform_xy_unit!(|self: Expand, area|{
|
||||
let area = self.content().layout(area);
|
||||
[area.x(), area.y(), area.w() + self.dx(), area.h() + self.dy()]
|
||||
});
|
||||
transform_xy_unit!(|self: Expand, area|self.content().layout([
|
||||
area.x(), area.y(), area.w() + self.dx(), area.h() + self.dy()
|
||||
].into()));
|
||||
|
||||
transform_xy_unit!(|self: Min, area|{
|
||||
let area = self.content().layout(area);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue