mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 22:17:07 +02:00
This commit is contained in:
parent
cf67185ffd
commit
799e497622
10 changed files with 456 additions and 460 deletions
|
|
@ -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::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue