fix x/y/xy ops; remove button_2/3

This commit is contained in:
facile pop culture reference 2026-08-08 21:46:05 +03:00
parent 799e497622
commit de591addb3
7 changed files with 138 additions and 144 deletions

View file

@ -179,76 +179,6 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
}
);
/// Some layout operations exist in multiple variants that take a single argument.
/// Their handling in [eval_view] is uniform and goes like this:
macro_rules! eval_enum ((
$name:literal, $output:ident, $state:ident, $value:expr, $Enum:ident {
$($v:literal => $V:ident),* $(,)?
}
) => {{
match $value {
$(Some($v) => $Enum::$V,)*
frag => unimplemented!("{}/{frag:?}", $name)
}
}});
/// Some layout operations exist in XY, X, and Y variants that take 3 or 2 arguments.
/// Their handling in [eval_view] is uniform and goes like this:
macro_rules! eval_xy (
// Valueless variant:
// (fill/x ...)
// (fill/y ...)
// (fill/xy ...)
(
$name:expr => $expr:expr, $head:expr, $output:ident, $state:ident,
$variant:expr, $xy:ident, $x:ident, $y:ident, $arg:expr,
) => {{
// frags.next(): 2nd slash-delimited fragment: /x, /y, /xy
let variant = $variant;
let thunk = draw(move|screen|$state.interpret(screen, &$arg));
match variant {
// X variant
Some("x") => thunk.$x().draw($output),
// Y variant
Some("y") => thunk.$y().draw($output),
// XY variant (can be omitted)
Some("xy") | None => thunk.$xy().draw($output),
// Other namespace members are invalid
frag => invalid_variant($name, frag, $expr, $head)
}
}};
// Variadic variant:
// (push/x n ...)
// (push/y n ...)
// (push/xy n m ...)
(
$name:expr => $expr:expr, $head:expr, $output:ident, $state:ident,
$variant:expr, $xy:ident, $x:ident, $y:ident, $arg0:expr, $arg1:expr, $arg2:expr,
) => {{
// frags.next(): 2nd slash-delimited fragment: /x, /y, /xy
let variant = $variant;
let thunk = draw(move|screen|$state.interpret(screen, &match variant {
Some("x") | Some("y") => $arg1,
Some("xy") | None => $arg2,
_ => panic!("{}: unsupported axis {variant:?}; try /x, /y, /xy", $name)
}));
match variant {
// X variant
Some("x") => thunk.$x($state.namespace($arg0?)?)
.draw($output),
// Y variant
Some("y") => thunk.$y($state.namespace($arg0?)?)
.draw($output),
// XY variant (can be omitted)
Some("xy") | None => thunk.$xy($state.namespace($arg0?)?, $state.namespace($arg1?)?)
.draw($output),
// Other namespace members are invalid
frag => invalid_variant($name, frag, $expr, $head)
}
}};
);
#[cfg(feature = "exit")] pub use self::exit::*;
#[cfg(feature = "exit")] mod exit {
use crate::*;