Refactor: Use pointers to refer to elements and regulators (#84)
All checks were successful
/ test (push) Successful in 2m25s
All checks were successful
/ test (push) Successful in 2m25s
Previously, dyna3 used storage keys to refer to elements, necessitating passing around element containers to various functions so that they could access the relevant elements. These storage keys have been replaced with reference-counted pointers, used for tasks like these: - Specifying the subjects of regulators. - Collecting the regulators each element is subject to - Handling selection. - Creating interface components. Also, systematizes the handling of serial numbers for entities, through a Serial trait. And updates to rust 1.86 and institutes explicit checking of the rust version. Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo> Reviewed-on: #84 Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net> Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
This commit is contained in:
parent
a2478febc1
commit
2adf4669f4
8 changed files with 288 additions and 270 deletions
|
@ -8,42 +8,41 @@ mod specified;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use rustc_hash::FxHashSet;
|
||||
use std::{collections::BTreeSet, rc::Rc};
|
||||
use sycamore::prelude::*;
|
||||
|
||||
use add_remove::AddRemove;
|
||||
use assembly::{Assembly, ElementKey};
|
||||
use assembly::{Assembly, Element};
|
||||
use display::Display;
|
||||
use outline::Outline;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {
|
||||
assembly: Assembly,
|
||||
selection: Signal<FxHashSet<ElementKey>>
|
||||
selection: Signal<BTreeSet<Rc<dyn Element>>>
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
fn new() -> AppState {
|
||||
AppState {
|
||||
assembly: Assembly::new(),
|
||||
selection: create_signal(FxHashSet::default())
|
||||
selection: create_signal(BTreeSet::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) {
|
||||
// in single-selection mode, select the given element. in multiple-selection
|
||||
// mode, toggle whether the given element is selected
|
||||
fn select(&self, element: &Rc<dyn Element>, multi: bool) {
|
||||
if multi {
|
||||
self.selection.update(|sel| {
|
||||
if !sel.remove(&key) {
|
||||
sel.insert(key);
|
||||
if !sel.remove(element) {
|
||||
sel.insert(element.clone());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self.selection.update(|sel| {
|
||||
sel.clear();
|
||||
sel.insert(key);
|
||||
sel.insert(element.clone());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue