mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
Chords, command refs and colours are plain data; the keymap generation is public
This commit is contained in:
Generated
+2
@@ -3110,6 +3110,8 @@ dependencies = [
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
"craft-settings",
|
||||
"craft-tracked",
|
||||
"craft-ui-macros",
|
||||
"craft-xml",
|
||||
"egui",
|
||||
"serde",
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ impl From<Rgba> 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,
|
||||
|
||||
@@ -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))))
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user