From 022bfa3e20c7333cab15e044dd0d52a6de4fafb0 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 23 Aug 2025 23:19:23 +0300 Subject: [PATCH 1/3] fix(proc): Command self type --- proc/src/proc_command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proc/src/proc_command.rs b/proc/src/proc_command.rs index 48ae0fe..12347ee 100644 --- a/proc/src/proc_command.rs +++ b/proc/src/proc_command.rs @@ -144,7 +144,7 @@ impl ToTokens for CommandDef { /// mutable pointer to [#state], invoking predefined operations /// and optionally returning undo history data. impl ::tengri::input::Command<#state> for #command_enum { - fn execute (self, state: &mut #state) -> Perhaps { + fn execute (&self, state: &mut #state) -> Perhaps { match self { #(#implementations)* } } } From 375b959e330b0e04f7a0ed8d6c079d0231e32c7f Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 23 Aug 2025 23:19:39 +0300 Subject: [PATCH 2/3] feat(input): add def_command --- input/input.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/input/input.rs b/input/input.rs index 2695a47..5a22800 100644 --- a/input/input.rs +++ b/input/input.rs @@ -26,8 +26,8 @@ flex_trait_mut!(Handle { }); pub trait Command: Send + Sync + Sized { - fn execute (self, state: &mut S) -> Perhaps; - fn delegate (self, state: &mut S, wrap: impl Fn(Self)->T) -> Perhaps + fn execute (&self, state: &mut S) -> Perhaps; + fn delegate (&self, state: &mut S, wrap: impl Fn(Self)->T) -> Perhaps where Self: Sized { Ok(self.execute(state)?.map(wrap)) @@ -35,10 +35,10 @@ pub trait Command: Send + Sync + Sized { } impl> Command for Option { - fn execute (self, _: &mut S) -> Perhaps { + fn execute (&self, _: &mut S) -> Perhaps { Ok(None) } - fn delegate (self, _: &mut S, _: impl Fn(Self)->U) -> Perhaps + fn delegate (&self, _: &mut S, _: impl Fn(Self)->U) -> Perhaps where Self: Sized { Ok(None) @@ -49,13 +49,30 @@ impl> Command for Option { #[macro_export] macro_rules! command { ($(<$($l:lifetime),+>)?|$self:ident:$Command:ty,$state:ident:$State:ty|$handler:expr) => { impl$(<$($l),+>)? ::tengri::input::Command<$State> for $Command { - fn execute ($self, $state: &mut $State) -> Perhaps { + fn execute (&$self, $state: &mut $State) -> Perhaps { Ok($handler) } } }; } +#[macro_export] macro_rules! def_command (($Command:ident: |$state:ident: $State:ty| { + $($Variant:ident$({$($arg:ident:$Arg:ty),+ $(,)?})?=>$body:expr),* $(,)? +})=>{ + #[derive(Debug)] + pub enum $Command { + $($Variant $({ $($arg: $Arg),* })?),* + } + impl Command<$State> for $Command { + fn execute (&self, $state: &mut $State) -> Perhaps { + match self { + $(Self::$Variant $({ $($arg),* })? => $body,)* + _ => unimplemented!("Command<{}>: {self:?}", stringify!($State)), + } + } + } +}); + /// Implement [Handle] for given `State` and `handler`. #[macro_export] macro_rules! handle { (|$self:ident:$State:ty,$input:ident|$handler:expr) => { From 446ec7a71477e1b9ca117b7a23759d6318eb2cf0 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 23 Aug 2025 23:19:49 +0300 Subject: [PATCH 3/3] feat(output): impl PartialEq for Measure --- output/src/space.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/output/src/space.rs b/output/src/space.rs index 3e1298b..3e850fd 100644 --- a/output/src/space.rs +++ b/output/src/space.rs @@ -208,6 +208,13 @@ pub struct Measure { pub y: Arc, } +impl PartialEq for Measure { + fn eq (&self, other: &Self) -> bool { + self.x.load(Relaxed) == other.x.load(Relaxed) && + self.y.load(Relaxed) == other.y.load(Relaxed) + } +} + // TODO: 🡘 🡙 ←🡙→ indicator to expand window when too small impl Content for Measure { fn render (&self, to: &mut E) {