From 0f9af5527cd7f18d73650916233ebbc6221b01e9 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 01:41:12 +0700 Subject: [PATCH] SelectMode, GroupHeads, PresetRowMenu and Selection are memo props, for the presets browser's memoized view --- crates/ui-contract/src/contract/collection/props.rs | 2 +- crates/ui-contract/src/contract/memo.rs | 10 ++++++++++ crates/ui-patterns/src/patterns/presets/model.rs | 2 +- crates/ui-widgets/src/tile_grid/grid.rs | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/src/contract/collection/props.rs b/crates/ui-contract/src/contract/collection/props.rs index a826fdbd0..e1892269d 100644 --- a/crates/ui-contract/src/contract/collection/props.rs +++ b/crates/ui-contract/src/contract/collection/props.rs @@ -11,7 +11,7 @@ use std::any::Any; use std::sync::Arc; /// What a collection lets the user select. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, crate::contract::MemoProps)] #[non_exhaustive] pub enum SelectMode { /// Nothing; the lead still moves. diff --git a/crates/ui-contract/src/contract/memo.rs b/crates/ui-contract/src/contract/memo.rs index 6343c0099..9734c9612 100644 --- a/crates/ui-contract/src/contract/memo.rs +++ b/crates/ui-contract/src/contract/memo.rs @@ -843,6 +843,16 @@ impl MemoProps for craft_behavior::Mixed { } /// The translator (`Words::generation`): words with the same generation read every word the same. +/// Every field (`#[non_exhaustive]`, so a field added later is listed here by hand): the selected keys, the lead and +/// the anchor. +impl MemoProps for craft_behavior::Selection { + fn key(&self, key: &mut MemoKey) { + self.items.key(key); + self.lead.key(key); + self.anchor.key(key); + } +} + impl MemoProps for craft_i18n::Words { fn key(&self, key: &mut MemoKey) { self.generation().key(key); diff --git a/crates/ui-patterns/src/patterns/presets/model.rs b/crates/ui-patterns/src/patterns/presets/model.rs index 8c0992355..1cccdaf67 100644 --- a/crates/ui-patterns/src/patterns/presets/model.rs +++ b/crates/ui-patterns/src/patterns/presets/model.rs @@ -144,7 +144,7 @@ pub struct PresetRow { } /// What the row menu of a browser or picker shows. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, crate::contract::MemoProps)] #[non_exhaustive] pub enum PresetRowMenu { /// Rename, Move to, Delete, a divider, then the host's `row_items`. diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index b82db7e1f..80f76333f 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -289,7 +289,7 @@ pub struct TileGrid<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { } /// How the groups of a grid or a list are set apart. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::contract::MemoProps)] #[non_exhaustive] pub enum GroupHeads { /// Every group has its titled head.