From 683fe06031224725b913c8ad3697d8e8bfec6c90 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 04:33:02 +0000 Subject: [PATCH] craft-layers: tree ids are plain data, keyed by their Hash --- crates/layers/src/ui/panel/body/rows.rs | 3 ++- crates/layers/src/ui/tree.rs | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/layers/src/ui/panel/body/rows.rs b/crates/layers/src/ui/panel/body/rows.rs index 74e144b32..8709aba62 100644 --- a/crates/layers/src/ui/panel/body/rows.rs +++ b/crates/layers/src/ui/panel/body/rows.rs @@ -31,9 +31,10 @@ pub(in crate::ui::panel) struct DisplayRow { /// What the display order derives from: the tree's tracked revision, the filter and the groups a reveal opens. A /// change of any of them builds the rows again; nothing else does. #[derive(MemoProps)] -pub(in crate::ui::panel) struct RowsKey<'a, Id: MemoProps> { +pub(in crate::ui::panel) struct RowsKey<'a, Id> { pub(in crate::ui::panel) tree: Revision, pub(in crate::ui::panel) filter: &'a LayerFilter, + #[memo_props(hash = "tree ids are plain model ids (LayerTree::Id: PlainData); Hash covers them")] pub(in crate::ui::panel) opened: &'a [Id], } diff --git a/crates/layers/src/ui/tree.rs b/crates/layers/src/ui/tree.rs index d8f10d5cd..b73560a0e 100644 --- a/crates/layers/src/ui/tree.rs +++ b/crates/layers/src/ui/tree.rs @@ -11,7 +11,7 @@ use std::hash::Hash; use craft_behavior::IconId; use craft_keymap::Mods; use craft_theme::LabelColor; -use craft_ui::contract::{Entry, MemoProps, PlainData, ReorderMove}; +use craft_ui::contract::{Entry, PlainData, ReorderMove}; use craft_ui::list::ThumbTarget; use super::filter::{EffectKind, LayerFilter, SmartSource}; @@ -22,6 +22,9 @@ use super::panel::MenuTarget; /// the panel derives from the tree. /// /// ```ignore +/// #[derive(Clone, PartialEq, Eq, Hash, Debug, PlainData)] +/// struct LayerId(u64); +/// /// #[derive(PlainData)] /// struct PhotoLayers { layers: LayerIndex, open: HashSet } /// impl LayerTree for PhotoLayers { @@ -36,9 +39,10 @@ use super::panel::MenuTarget; /// [`children`](Self::children) and [`is_open`](Self::is_open) are walked to build the display order, and only when the /// tracked revision, the filter or a reveal's opens changed. pub trait LayerTree: PlainData { - /// The app's layer id: the key of a row, of its thumbnails and of every event. It feeds the memo key of the - /// display order when a reveal opens groups. - type Id: Clone + Eq + Hash + Debug + Send + Sync + MemoProps + 'static; + /// The app's layer id: the key of a row, of its thumbnails and of every event. It is plain model data + /// (`#[derive(PlainData)]`), so the panel keys it by its `Hash`, including in the memo key of the display order + /// when a reveal opens groups. + type Id: Clone + Eq + Hash + Debug + Send + Sync + PlainData + 'static; /// Children of `parent` (`None`: the top level), topmost first. The app leaves out what the /// panel never shows: layers outside an Isolate Layers set, a Type Mask session's working text.