Application prototype #14

Merged
glen merged 101 commits from app-proto into main 2024-10-21 23:38:28 +00:00
3 changed files with 44 additions and 32 deletions
Showing only changes of commit e6d1e0b865 - Show all commits

View File

@ -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())

View 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>>
}

View File

@ -1,6 +1,7 @@
use sycamore::prelude::*;
mod app; mod app;
mod assembly;
use sycamore::prelude::*;
use app::App; use app::App;