App: store selection in hash map

Switch `Assembly.elements` to a hash map too, since that's probably
closer to what we'll want in the future.
This commit is contained in:
Aaron Fenyes 2024-09-19 16:08:55 -07:00
parent 96afad0c97
commit 96f8b6b5f3
5 changed files with 89 additions and 53 deletions

View file

@ -3,6 +3,7 @@ mod display;
mod outline;
use nalgebra::DVector;
use rustc_hash::{FxHashMap, FxHashSet};
use sycamore::prelude::*;
use assembly::{Assembly, Element};
@ -11,40 +12,52 @@ use outline::Outline;
#[derive(Clone)]
struct AppState {
assembly: Assembly
assembly: Assembly,
selection: Signal<FxHashSet<String>>
}
fn main() {
sycamore::render(|| {
provide_context(
AppState {
assembly: Assembly {
elements: create_signal(vec![
Element {
id: String::from("wing_a"),
label: String::from("Wing A"),
color: [1.00_f32, 0.25_f32, 0.00_f32],
rep: DVector::<f64>::from_column_slice(&[0.5, 0.5, 0.0, 0.5, -0.25]),
selected: create_signal(false)
},
Element {
id: String::from("wing_b"),
label: String::from("Wing B"),
color: [0.00_f32, 0.25_f32, 1.00_f32],
rep: DVector::<f64>::from_column_slice(&[-0.5, -0.5, 0.0, 0.5, -0.25]),
selected: create_signal(false)
},
Element {
id: String::from("central"),
label: String::from("Central"),
color: [0.75_f32, 0.75_f32, 0.75_f32],
rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.4, -0.625]),
selected: create_signal(false)
}
])
let state = AppState {
assembly: Assembly {
elements: create_signal(FxHashMap::default())
},
selection: create_signal(FxHashSet::default())
};
state.assembly.elements.update(
|elts| elts.insert(
"wing_a".to_string(),
Element {
id: String::from("wing_a"),
label: String::from("Wing A"),
color: [1.00_f32, 0.25_f32, 0.00_f32],
rep: DVector::<f64>::from_column_slice(&[0.5, 0.5, 0.0, 0.5, -0.25])
}
}
)
);
state.assembly.elements.update(
|elts| elts.insert(
"wing_b".to_string(),
Element {
id: String::from("wing_b"),
label: String::from("Wing B"),
color: [0.00_f32, 0.25_f32, 1.00_f32],
rep: DVector::<f64>::from_column_slice(&[-0.5, -0.5, 0.0, 0.5, -0.25])
},
)
);
state.assembly.elements.update(
|elts| elts.insert(
"central".to_string(),
Element {
id: String::from("central"),
label: String::from("Central"),
color: [0.75_f32, 0.75_f32, 0.75_f32],
rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.4, -0.625])
}
)
);
provide_context(state);
view! {
Outline {}