Integrate engine into application prototype #15
@ -7,13 +7,17 @@ use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
||||
|
||||
use crate::engine::{realize_gram, PartialMatrix};
|
||||
|
||||
// the types of the keys we use to access an assembly's elements and constraints
|
||||
pub type ElementKey = usize;
|
||||
pub type ConstraintKey = usize;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct Element {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
pub color: [f32; 3],
|
||||
pub representation: DVector<f64>,
|
||||
pub constraints: BTreeSet<usize>,
|
||||
pub constraints: BTreeSet<ConstraintKey>,
|
||||
|
||||
// internal properties, not reflected in any view
|
||||
pub index: usize
|
||||
@ -21,7 +25,7 @@ pub struct Element {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Constraint {
|
||||
pub subjects: (usize, usize),
|
||||
pub subjects: (ElementKey, ElementKey),
|
||||
pub rep: Signal<f64>,
|
||||
pub rep_text: Signal<String>,
|
||||
pub rep_valid: Signal<bool>,
|
||||
@ -36,7 +40,7 @@ pub struct Assembly {
|
||||
pub constraints: Signal<Slab<Constraint>>,
|
||||
|
||||
// indexing
|
||||
pub elements_by_id: Signal<FxHashMap<String, usize>>
|
||||
pub elements_by_id: Signal<FxHashMap<String, ElementKey>>
|
||||
}
|
||||
|
||||
impl Assembly {
|
||||
|
@ -8,14 +8,14 @@ use rustc_hash::FxHashSet;
|
||||
use sycamore::prelude::*;
|
||||
|
||||
use add_remove::AddRemove;
|
||||
use assembly::Assembly;
|
||||
use assembly::{Assembly, ElementKey};
|
||||
use display::Display;
|
||||
use outline::Outline;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {
|
||||
assembly: Assembly,
|
||||
selection: Signal<FxHashSet<usize>>
|
||||
selection: Signal<FxHashSet<ElementKey>>
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
|
@ -150,7 +150,7 @@ pub fn Outline() -> View {
|
||||
ul(class="constraints") {
|
||||
Keyed(
|
||||
list=elt.constraints.into_iter().collect::<Vec<_>>(),
|
||||
view=move |c_key: usize| {
|
||||
view=move |c_key| {
|
||||
let c_state = use_context::<AppState>();
|
||||
let assembly = &c_state.assembly;
|
||||
let cst = assembly.constraints.with(|csts| csts[c_key].clone());
|
||||
|
Loading…
Reference in New Issue
Block a user