fix and coverage for layout modifiers
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
facile pop culture reference 2026-08-06 18:29:03 +03:00
parent cf67185ffd
commit 799e497622
10 changed files with 456 additions and 460 deletions

View file

@ -96,6 +96,53 @@ impl Sizer {
}
}
macro_rules! def_layout_modifier {
(
$Trait:ident ($fn_x:ident $fn_y:ident $fn_xy:ident),
$Struct:ident { $X:ident $Y:ident $XY:ident } $kw_name:ident $name:literal
|$self:ident, $to:ident| $body:block
) => {
impl<S: Screen, T: Draw<S>> $Trait<S> for T {}
pub trait $Trait<S: Screen>: Draw<S> + Sized {
fn $fn_x <N: Into<Option<S::Unit>> + Copy> (self, x: N)
-> $Struct<S, Self, N> { $Struct::$X(self, x) }
fn $fn_y <N: Into<Option<S::Unit>> + Copy> (self, y: N)
-> $Struct<S, Self, N> { $Struct::$Y(self, y) }
fn $fn_xy <N: Into<Option<S::Unit>> + Copy> (self, x: N, y: N)
-> $Struct<S, Self, N> { $Struct::$XY(self, x, y) }
}
pub enum $Struct<S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
__(PhantomData<S>), $X(I, X), $Y(I, X), $XY(I, X, X),
}
impl <S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for $Struct<S, I, X> {
fn draw (&$self, $to: &mut S) -> Perhaps<XYWH<S::Unit>> {
$body
}
}
fn_kw_layout!($kw_name |state, output, expr| {
let head = expr.head()?;
let mut frags = head.src()?.unwrap_or_default().split("/");
Ok(matches!(expr.head()?, Some("exact")).then(||{
let args = expr.tail();
let arg0 = args.head();
let tail0 = args.tail();
let arg1 = tail0.head();
let tail1 = tail0.tail();
let arg2 = tail1.head();
eval_xy!(
$name => expr, head, output, state, frags.next(),
$fn_xy, $fn_x, $fn_y,
arg0, arg1, arg2,
)
}).transpose()?.flatten())
});
}
}
mod area; pub use self::area::*;
mod axis; pub use self::axis::*;
mod azimuth; pub use self::azimuth::*;