2024-09-12 22:24:41 +00:00
|
|
|
use nalgebra::DVector;
|
|
|
|
use sycamore::{prelude::*, web::tags::div};
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq)]
|
|
|
|
struct Element {
|
2024-09-13 05:36:54 +00:00
|
|
|
id: String,
|
|
|
|
label: String,
|
|
|
|
color: [f32; 3],
|
2024-09-12 22:24:41 +00:00
|
|
|
rep: DVector<f64>,
|
|
|
|
}
|
|
|
|
|
2024-09-13 05:39:21 +00:00
|
|
|
struct AppState {
|
2024-09-12 22:24:41 +00:00
|
|
|
elements: Signal<Vec<Element>>
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component]
|
2024-09-13 05:39:21 +00:00
|
|
|
pub fn App() -> View {
|
|
|
|
let state = AppState {
|
2024-09-12 22:24:41 +00:00
|
|
|
elements: create_signal(vec![
|
|
|
|
Element {
|
2024-09-13 05:36:54 +00:00
|
|
|
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])
|
2024-09-12 22:24:41 +00:00
|
|
|
},
|
|
|
|
Element {
|
2024-09-13 05:36:54 +00:00
|
|
|
id: String::from("wing_a"),
|
|
|
|
label: String::from("Wing A"),
|
|
|
|
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])
|
2024-09-12 22:24:41 +00:00
|
|
|
},
|
|
|
|
Element {
|
2024-09-13 05:36:54 +00:00
|
|
|
id: String::from("wing_b"),
|
|
|
|
label: String::from("Wing B"),
|
|
|
|
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])
|
2024-09-12 22:24:41 +00:00
|
|
|
}
|
|
|
|
])
|
|
|
|
};
|
|
|
|
|
|
|
|
view! {
|
|
|
|
ul {
|
|
|
|
Keyed(
|
|
|
|
list=state.elements,
|
|
|
|
view=|elt| {
|
2024-09-13 05:36:54 +00:00
|
|
|
let label = elt.label.clone();
|
2024-09-12 22:24:41 +00:00
|
|
|
let rep_components = elt.rep.iter().map(
|
|
|
|
|u| View::from(div().children(u.to_string().replace("-", "\u{2212}")))
|
|
|
|
).collect::<Vec<_>>();
|
|
|
|
view! {
|
|
|
|
li {
|
2024-09-13 05:36:54 +00:00
|
|
|
div(class="elt-label") { (label) }
|
2024-09-12 22:24:41 +00:00
|
|
|
div(class="elt-rep") { (rep_components) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-09-13 05:36:54 +00:00
|
|
|
key=|elt| elt.id.clone()
|
2024-09-12 22:24:41 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|