Click the display to select spheres #25

Merged
glen merged 2 commits from select-in-display into main 2024-11-27 05:02:07 +00:00
3 changed files with 20 additions and 26 deletions
Showing only changes of commit f4c9d3d7f4 - Show all commits

View File

@ -506,20 +506,7 @@ pub fn Display() -> View {
// if we clicked something, select it // if we clicked something, select it
match clicked { match clicked {
Some((key, _)) => { Some((key, _)) => state.select(key, event.shift_key()),
if event.shift_key() {
state.selection.update(|sel| {
if !sel.remove(&key) {
sel.insert(key);
}
})
} else {
state.selection.update(|sel| {
sel.clear();
sel.insert(key);
})
}
},
None => state.selection.update(|sel| sel.clear()) None => state.selection.update(|sel| sel.clear())
}; };
} }

View File

@ -25,6 +25,24 @@ impl AppState {
selection: create_signal(FxHashSet::default()) selection: create_signal(FxHashSet::default())
} }
} }
// in single-selection mode, select the element with the given key. in
// multiple-selection mode, toggle whether the element with the given key
// is selected
fn select(&self, key: ElementKey, multi: bool) {
if multi {
self.selection.update(|sel| {
if !sel.remove(&key) {
sel.insert(key);
}
});
} else {
self.selection.update(|sel| {
sel.clear();
sel.insert(key);
});
}
}
} }
fn main() { fn main() {

View File

@ -83,18 +83,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
move |event: KeyboardEvent| { move |event: KeyboardEvent| {
match event.key().as_str() { match event.key().as_str() {
"Enter" => { "Enter" => {
if event.shift_key() { state.select(key, event.shift_key());
state.selection.update(|sel| {
if !sel.remove(&key) {
sel.insert(key);
}
});
} else {
state.selection.update(|sel| {
sel.clear();
sel.insert(key);
});
}
event.prevent_default(); event.prevent_default();
}, },
"ArrowRight" if constrained.get() => { "ArrowRight" if constrained.get() => {