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,47 +2,42 @@ 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 {
elements: create_signal(vec![ assembly: Assembly {
Element { elements: create_signal(vec![
id: String::from("wing_a"), Element {
label: String::from("Wing A"), id: String::from("wing_a"),
color: [1.00_f32, 0.25_f32, 0.00_f32], label: String::from("Wing A"),
rep: DVector::<f64>::from_column_slice(&[0.5, 0.5, 0.0, 0.5, -0.25]) 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])
Element { },
id: String::from("wing_b"), Element {
label: String::from("Wing B"), id: String::from("wing_b"),
color: [1.00_f32, 0.25_f32, 0.00_f32], label: String::from("Wing B"),
rep: DVector::<f64>::from_column_slice(&[-0.5, -0.5, 0.0, 0.5, -0.25]) 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])
Element { },
id: String::from("central"), Element {
label: String::from("Central"), id: String::from("central"),
color: [0.75_f32, 0.75_f32, 0.75_f32], label: String::from("Central"),
rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.25, -1.0]) color: [0.75_f32, 0.75_f32, 0.75_f32],
} 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;