dyna3/app-proto/sketch-outline/src/main.rs
Aaron Fenyes 96f8b6b5f3 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.
2024-09-19 16:08:55 -07:00

67 lines
No EOL
1.9 KiB
Rust

mod assembly;
mod display;
mod outline;
use nalgebra::DVector;
use rustc_hash::{FxHashMap, FxHashSet};
use sycamore::prelude::*;
use assembly::{Assembly, Element};
use display::Display;
use outline::Outline;
#[derive(Clone)]
struct AppState {
assembly: Assembly,
selection: Signal<FxHashSet<String>>
}
fn main() {
sycamore::render(|| {
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 {}
Display {}
}
});
}