diff --git a/Cargo.lock b/Cargo.lock index 881c49f6c..cb611a042 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3110,6 +3110,8 @@ dependencies = [ "craft-host", "craft-i18n", "craft-settings", + "craft-tracked", + "craft-ui-macros", "craft-xml", "egui", "serde", diff --git a/crates/keymap/Cargo.toml b/crates/keymap/Cargo.toml index 6a693d2b0..61beb609a 100644 --- a/crates/keymap/Cargo.toml +++ b/crates/keymap/Cargo.toml @@ -19,6 +19,9 @@ craft-xml = { workspace = true } egui = { workspace = true, optional = true } craft-i18n = { workspace = true } craft-host = { workspace = true } +# Chords and command refs are held in `Tracked` models. +craft-tracked = { workspace = true } +craft-ui-macros = { workspace = true } [dev-dependencies] # `serde` for setting `RawInput` fields only the suite's egui fork has. diff --git a/crates/keymap/src/chord.rs b/crates/keymap/src/chord.rs index 86c410798..6a069d7db 100644 --- a/crates/keymap/src/chord.rs +++ b/crates/keymap/src/chord.rs @@ -23,7 +23,7 @@ macro_rules! keys { /// A key on the keyboard, independent of any UI toolkit. /// /// Digits are the main row; numeric keypad keys map to the same keys. - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, craft_ui_macros::PlainData)] #[non_exhaustive] pub enum Key { $(#[allow(missing_docs)] $variant),* @@ -388,7 +388,7 @@ impl<'de> Deserialize<'de> for Key { } /// Modifier keys held with a chord's key. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, craft_ui_macros::PlainData)] pub struct Mods { /// The command modifier: ⌘ on macOS, Ctrl on Windows and Linux. pub cmd: bool, @@ -453,7 +453,7 @@ impl Mods { } /// A key with modifiers. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, craft_ui_macros::PlainData)] pub struct Chord { /// The modifiers held with the key. pub mods: Mods, diff --git a/crates/keymap/src/command.rs b/crates/keymap/src/command.rs index ae0095f7e..8ee338d32 100644 --- a/crates/keymap/src/command.rs +++ b/crates/keymap/src/command.rs @@ -10,13 +10,14 @@ use serde_json::Value; pub const MAX_KEY: usize = 256; /// A command id with the parameters a binding runs it with. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, craft_ui_macros::PlainData)] #[serde(rename_all = "camelCase")] pub struct CommandRef { /// The command's id. pub id: String, /// `Null` for no parameters. #[serde(default)] + #[plain_data(assume = "a JSON value owns its data and has no interior mutability")] pub params: Value, } diff --git a/crates/theme/src/color.rs b/crates/theme/src/color.rs index d0a5eff24..272e7019e 100644 --- a/crates/theme/src/color.rs +++ b/crates/theme/src/color.rs @@ -226,7 +226,7 @@ impl From for Oklch { /// An encoded sRGB colour with float channels in 0..=1 and straight alpha: the value a colour /// picker edits. Eight bits lose the precision that HSB and OKLCH edits need. -#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize, craft_ui_macros::PlainData)] pub struct Srgba { /// Red, encoded. pub r: f32, diff --git a/crates/ui-contract/src/runtime/commands/board.rs b/crates/ui-contract/src/runtime/commands/board.rs index e80cfddde..97cb94bbc 100644 --- a/crates/ui-contract/src/runtime/commands/board.rs +++ b/crates/ui-contract/src/runtime/commands/board.rs @@ -1113,11 +1113,18 @@ pub(crate) fn edit_chords(ctx: &Context) -> Arc<[(EditCommand, Chord)]> { with(ctx, |board| board.keymap.as_ref().map(|cache| Arc::clone(&cache.edit_chords)).unwrap_or_default()) } -/// The generation of the window's keymap: it moves each time a new keymap is built. -pub(crate) fn keymap_generation(ctx: &Context) -> u64 { +/// The generation of the window's keymap without noting a read: it moves each time a new keymap is built. +pub(crate) fn keymap_built(ctx: &Context) -> u64 { with(ctx, |board| board.keymaps) } +/// The generation of the window's keymap, for a key that holds what is derived from its chords: it moves each time a +/// new keymap is built. The caller's view reads the keymap, so a change of it runs the view. +pub fn keymap_generation(ctx: &Context) -> u64 { + crate::runtime::replay::note_input(ctx, crate::runtime::inputs::Input::Keymap); + keymap_built(ctx) +} + /// Whether the queue holds a command for one of `instances`: only a run of the view they registered in takes it. pub(crate) fn queued_for(ctx: &Context, instances: &[Id]) -> bool { !instances.is_empty() && with(ctx, |board| board.queue.iter().any(|fired| fired.target.is_some_and(|target| instances.contains(&target)))) diff --git a/crates/ui-contract/src/runtime/commands/mod.rs b/crates/ui-contract/src/runtime/commands/mod.rs index c53e067da..a41db0e7e 100644 --- a/crates/ui-contract/src/runtime/commands/mod.rs +++ b/crates/ui-contract/src/runtime/commands/mod.rs @@ -29,12 +29,12 @@ pub(crate) use board::{ begin, binds_scoped, edit_chords, end, install, note_focus, register_instance, set_input, take_delivered, take_fired, window_shortcuts, }; #[doc(hidden)] -pub use board::{bound_around, take_around}; +pub use board::{bound_around, keymap_generation, take_around}; #[cfg(feature = "testing")] #[doc(hidden)] pub use board::{chord_text_builds, keymap_builds}; pub(crate) use board::{fire_bound, fire_resolved, resolve_bound, resolve_scoped}; -pub(crate) use board::{keymap_generation, queued_for}; +pub(crate) use board::{keymap_built, queued_for}; use crate::contract::{MemoKey, MemoProps, PlainData, Revision, Tracked}; use craft_behavior::CommandFlags; diff --git a/crates/ui-contract/src/runtime/inputs.rs b/crates/ui-contract/src/runtime/inputs.rs index 8b4e3eb3d..4c3d8d51c 100644 --- a/crates/ui-contract/src/runtime/inputs.rs +++ b/crates/ui-contract/src/runtime/inputs.rs @@ -124,7 +124,7 @@ pub(crate) fn generation(ctx: &Context, input: Input) -> u64 { Input::Drag => observe(ctx, input, crate::runtime::drag::state(ctx)), Input::Focus => observe(ctx, input, crate::runtime::focus::focus_state(ctx)), Input::Overlays => observe(ctx, input, crate::runtime::overlay::open_state(ctx)), - Input::Keymap => return crate::runtime::commands::keymap_generation(ctx), + Input::Keymap => return crate::runtime::commands::keymap_built(ctx), Input::Modifiers | Input::Pointer | Input::Shell | Input::Keyboard | Input::Scroll => {} } with(ctx, |generations| generations.gens[input as usize])