From e19e64edba55c73518da646ef72960cace87ba52 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 01:51:38 +0000 Subject: [PATCH] menu: Gate and ModalRules are props of the runtime's command gate Gate derives MemoProps. ModalRules keys on its plain fields and its revision, which stands for the pending closure the derive cannot take; design-lint allows that one hand-written impl. --- crates/design-lint/src/workspace.rs | 3 +++ crates/menu/src/driver.rs | 6 ++++-- crates/menu/src/modal.rs | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/design-lint/src/workspace.rs b/crates/design-lint/src/workspace.rs index 80d4f53f8..5425859d0 100644 --- a/crates/design-lint/src/workspace.rs +++ b/crates/design-lint/src/workspace.rs @@ -137,6 +137,9 @@ const NO_GLOBAL_STATE_PREFIXES: &[&str] = &[ const NO_GLOBAL_STATE: &[(&str, &str)] = &[ // The trait's home crate: it implements `MemoProps` by hand for std and framework value types. ("crates/ui-contract/src/contract/memo.rs", "MemoProps"), + // Settled fact: `ModalRules` holds a closure the derive cannot take; it keys on its plain fields and the revision + // the app moves with every rule change, which stands for the closure. + ("crates/menu/src/modal.rs", "MemoProps"), // Settled fact: constant font bytes, decompressed once from compile-time input and immutable after init. ("crates/ui-contract/src/fonts/defaults.rs", "HACK"), ("crates/ui-contract/src/fonts/defaults.rs", "EGUI_ICONS"), diff --git a/crates/menu/src/driver.rs b/crates/menu/src/driver.rs index 2d2c0c347..3c79dc831 100644 --- a/crates/menu/src/driver.rs +++ b/crates/menu/src/driver.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; use craft_keymap::{Chord, CommandRef, Key, Mods}; +use craft_ui::contract::MemoProps; use craft_ui::runtime::windows::{KeyEquivalent, WindowAction, WindowHost}; use crate::layout::{Clash, Layout}; @@ -45,8 +46,9 @@ pub enum ClipboardKeys { Raw, } -/// What may run from the menus this frame, set by the app. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +/// What may run from the menus this frame, set by the app. As props of the runtime's command gate, every flag feeds +/// the key. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, MemoProps)] #[non_exhaustive] pub struct Gate { /// A modal dialog is open. diff --git a/crates/menu/src/modal.rs b/crates/menu/src/modal.rs index a633b5ab4..821118fcb 100644 --- a/crates/menu/src/modal.rs +++ b/crates/menu/src/modal.rs @@ -12,6 +12,7 @@ use std::fmt; use std::sync::Arc; use craft_keymap::CommandRef; +use craft_ui::contract::{MemoKey, MemoProps}; use crate::driver::Gate; use crate::model::{Builtin, Item}; @@ -49,7 +50,8 @@ pub struct ModalRules { /// run. `None`: no pending operation. pub pending: Option, /// The caller's count of rule changes. A rule holds a closure and cannot be compared, so the - /// caller says when the rules changed; the menu skips the resync while it stays the same. + /// caller says when the rules changed; the menu skips the resync, and the runtime's command gate keeps its answers, + /// while it stays the same. pub revision: u64, } @@ -86,6 +88,18 @@ impl ModalRules { } } +/// As props of the runtime's command gate: the plain fields and [`ModalRules::revision`], which stands for the +/// [`ModalRules::pending`] closure. The derive cannot take the closure, and the revision is the caller's count of rule +/// changes, so equal keys mean equal rules as long as the caller moves it with every change. +impl MemoProps for ModalRules { + fn key(&self, key: &mut MemoKey) { + let ModalRules { in_dialogs, workspace, pending: _, revision } = self; + in_dialogs.key(key); + workspace.key(key); + revision.key(key); + } +} + impl fmt::Debug for ModalRules { // new: `PendingRule` is a closure; print whether one is set. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {