App: pass app state into outline as context
This commit is contained in:
parent
49170671b4
commit
959e4cc8b5
@ -10,6 +10,7 @@ pub struct Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// a complete, view-independent description of an assembly
|
// a complete, view-independent description of an assembly
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Assembly {
|
pub struct Assembly {
|
||||||
// the order of the elements is arbitrary, and it could change at any time
|
// the order of the elements is arbitrary, and it could change at any time
|
||||||
pub elements: Signal<Vec<Element>>
|
pub elements: Signal<Vec<Element>>
|
||||||
|
@ -1,16 +1,50 @@
|
|||||||
mod app;
|
|
||||||
mod assembly;
|
mod assembly;
|
||||||
mod display;
|
mod display;
|
||||||
|
mod outline;
|
||||||
|
|
||||||
|
use nalgebra::DVector;
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
use app::App;
|
use assembly::{Assembly, Element};
|
||||||
use display::Display;
|
use display::Display;
|
||||||
|
use outline::Outline;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct AppState {
|
||||||
|
assembly: Assembly
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
sycamore::render(|| {
|
sycamore::render(|| {
|
||||||
|
provide_context(
|
||||||
|
AppState {
|
||||||
|
assembly: Assembly {
|
||||||
|
elements: create_signal(vec![
|
||||||
|
Element {
|
||||||
|
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])
|
||||||
|
},
|
||||||
|
Element {
|
||||||
|
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])
|
||||||
|
},
|
||||||
|
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])
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
App {}
|
Outline {}
|
||||||
Display {}
|
Display {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,39 +1,11 @@
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nalgebra::DVector;
|
|
||||||
use sycamore::{prelude::*, web::tags::div};
|
use sycamore::{prelude::*, web::tags::div};
|
||||||
|
|
||||||
use crate::assembly::{Assembly, Element};
|
use crate::AppState;
|
||||||
|
|
||||||
struct AppState {
|
|
||||||
assembly: Assembly
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> View {
|
pub fn Outline() -> View {
|
||||||
let state = AppState {
|
let state = use_context::<AppState>();
|
||||||
assembly: Assembly {
|
|
||||||
elements: create_signal(vec![
|
|
||||||
Element {
|
|
||||||
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])
|
|
||||||
},
|
|
||||||
Element {
|
|
||||||
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])
|
|
||||||
},
|
|
||||||
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
|
// sort the elements alphabetically by ID
|
||||||
let elements_sorted = create_memo(move ||
|
let elements_sorted = create_memo(move ||
|
Loading…
Reference in New Issue
Block a user