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