Skip to content

Commit

Permalink
#51. Add view_id
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Aug 19, 2023
1 parent 202a75c commit c5979a3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -178,7 +180,10 @@ impl Context {
assert!(path.len() == 1);
let keep_set = HashSet::<ViewId>::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![];
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c5979a3

Please sign in to comment.