From c5979a34b193a1e76c10488bdf1810852bab48f3 Mon Sep 17 00:00:00 2001 From: Taylor Holliday Date: Sat, 19 Aug 2023 10:39:33 -0700 Subject: [PATCH] #51. Add view_id --- src/context.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/context.rs b/src/context.rs index 0a4bc21..59307b9 100644 --- a/src/context.rs +++ b/src/context.rs @@ -3,8 +3,10 @@ use euclid::*; use std::any::Any; use std::any::TypeId; use std::collections::{HashMap, HashSet}; +use std::hash::{Hash, Hasher}; use std::iter::FromIterator; use std::ops; +use std::collections::hash_map::DefaultHasher; pub type LocalSpace = vger::defs::LocalSpace; pub type WorldSpace = vger::defs::WorldSpace; @@ -178,7 +180,10 @@ impl Context { assert!(path.len() == 1); let keep_set = HashSet::::from_iter(keep); self.state_map.retain(|k, _| keep_set.contains(k)); - self.layout.retain(|k, _| keep_set.contains(&hash(k))); + + let mut new_layout = self.layout.clone(); + new_layout.retain(|k, _| keep_set.contains(&self.view_id(k))); + self.layout = new_layout; // Get a new accesskit tree. let mut nodes = vec![]; @@ -331,6 +336,16 @@ impl Context { view.commands(&mut path, self, cmds); } + pub(crate) fn view_id(&mut self, path: &IdPath) -> ViewId { + let mut hasher = DefaultHasher::new(); + for id in path { + hasher.write_u64(*id); + } + ViewId { + id: hasher.finish(), + } + } + pub(crate) fn update_layout(&mut self, path: &IdPath, layout_box: LayoutBox) { match self.layout.get_mut(path) { Some(bref) => *bref = layout_box,