Outline: encapsulate assembly data
This commit is contained in:
parent
d481181ef8
commit
e6d1e0b865
@ -2,22 +2,16 @@ use itertools::Itertools;
|
|||||||
use nalgebra::DVector;
|
use nalgebra::DVector;
|
||||||
use sycamore::{prelude::*, web::tags::div};
|
use sycamore::{prelude::*, web::tags::div};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
use crate::assembly::{Assembly, Element};
|
||||||
struct Element {
|
|
||||||
id: String,
|
|
||||||
label: String,
|
|
||||||
color: [f32; 3],
|
|
||||||
rep: DVector<f64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct AppState {
|
struct AppState {
|
||||||
// the order of the elements is arbitrary, and it could change at any time
|
assembly: Assembly
|
||||||
elements: Signal<Vec<Element>>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> View {
|
pub fn App() -> View {
|
||||||
let state = AppState {
|
let state = AppState {
|
||||||
|
assembly: Assembly {
|
||||||
elements: create_signal(vec![
|
elements: create_signal(vec![
|
||||||
Element {
|
Element {
|
||||||
id: String::from("wing_a"),
|
id: String::from("wing_a"),
|
||||||
@ -38,11 +32,12 @@ pub fn App() -> View {
|
|||||||
rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.25, -1.0])
|
rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.25, -1.0])
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// sort the elements alphabetically by ID
|
// sort the elements alphabetically by ID
|
||||||
let elements_sorted = create_memo(move ||
|
let elements_sorted = create_memo(move ||
|
||||||
state.elements
|
state.assembly.elements
|
||||||
.get_clone()
|
.get_clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.sorted_by_key(|elt| elt.id.clone())
|
.sorted_by_key(|elt| elt.id.clone())
|
||||||
|
16
app-proto/sketch-outline/src/assembly.rs
Normal file
16
app-proto/sketch-outline/src/assembly.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use nalgebra::DVector;
|
||||||
|
use sycamore::reactive::Signal;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct Element {
|
||||||
|
pub id: String,
|
||||||
|
pub label: String,
|
||||||
|
pub color: [f32; 3],
|
||||||
|
pub rep: DVector<f64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// a complete, view-independent description of an assembly
|
||||||
|
pub struct Assembly {
|
||||||
|
// the order of the elements is arbitrary, and it could change at any time
|
||||||
|
pub elements: Signal<Vec<Element>>
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
use sycamore::prelude::*;
|
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
|
mod assembly;
|
||||||
|
|
||||||
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
use app::App;
|
use app::App;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user