Application prototype #14
@ -8,6 +8,7 @@ edition = "2021"
|
|||||||
default = ["console_error_panic_hook"]
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
itertools = "0.13.0"
|
||||||
js-sys = "0.3.70"
|
js-sys = "0.3.70"
|
||||||
nalgebra = "0.33.0"
|
nalgebra = "0.33.0"
|
||||||
sycamore = "0.9.0-beta.3"
|
sycamore = "0.9.0-beta.3"
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use itertools::Itertools;
|
||||||
use nalgebra::DVector;
|
use nalgebra::DVector;
|
||||||
use sycamore::{prelude::*, web::tags::div};
|
use sycamore::{prelude::*, web::tags::div};
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ struct Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct AppState {
|
struct AppState {
|
||||||
|
// the order of the elements is arbitrary, and it could change at any time
|
||||||
elements: Signal<Vec<Element>>
|
elements: Signal<Vec<Element>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,12 +19,6 @@ struct AppState {
|
|||||||
pub fn App() -> View {
|
pub fn App() -> View {
|
||||||
let state = AppState {
|
let state = AppState {
|
||||||
elements: create_signal(vec![
|
elements: create_signal(vec![
|
||||||
Element {
|
|
||||||
id: String::from("central"),
|
|
||||||
label: String::from("Central"),
|
|
||||||
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])
|
|
||||||
},
|
|
||||||
Element {
|
Element {
|
||||||
id: String::from("wing_a"),
|
id: String::from("wing_a"),
|
||||||
label: String::from("Wing A"),
|
label: String::from("Wing A"),
|
||||||
@ -34,14 +30,29 @@ pub fn App() -> View {
|
|||||||
label: String::from("Wing B"),
|
label: String::from("Wing B"),
|
||||||
color: [1.00_f32, 0.25_f32, 0.00_f32],
|
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])
|
rep: DVector::<f64>::from_column_slice(&[-0.5, -0.5, 0.0, 0.5, -0.25])
|
||||||
|
},
|
||||||
|
Element {
|
||||||
|
id: String::from("central"),
|
||||||
|
label: String::from("Central"),
|
||||||
|
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
|
||||||
|
let elements_sorted = create_memo(move ||
|
||||||
|
state.elements
|
||||||
|
.get_clone()
|
||||||
|
.into_iter()
|
||||||
|
.sorted_by_key(|elt| elt.id.clone())
|
||||||
|
.collect()
|
||||||
|
);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
ul {
|
ul {
|
||||||
Keyed(
|
Keyed(
|
||||||
list=state.elements,
|
list=elements_sorted,
|
||||||
view=|elt| {
|
view=|elt| {
|
||||||
let label = elt.label.clone();
|
let label = elt.label.clone();
|
||||||
let rep_components = elt.rep.iter().map(
|
let rep_components = elt.rep.iter().map(
|
||||||
|
Loading…
Reference in New Issue
Block a user