forked from StudioInfinity/dyna3
Outline: start on editor state and outline view
This commit is contained in:
parent
d3c9a08d22
commit
336b940471
6 changed files with 165 additions and 0 deletions
61
app-proto/sketch-outline/src/editor.rs
Normal file
61
app-proto/sketch-outline/src/editor.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
use nalgebra::DVector;
|
||||
use sycamore::{prelude::*, web::tags::div};
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
struct Element {
|
||||
id: i64,
|
||||
name: String,
|
||||
rep: DVector<f64>,
|
||||
color: [f32; 3]
|
||||
}
|
||||
|
||||
struct EditorState {
|
||||
elements: Signal<Vec<Element>>
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn Editor() -> View {
|
||||
let state = EditorState {
|
||||
elements: create_signal(vec![
|
||||
Element {
|
||||
id: 1,
|
||||
name: 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]
|
||||
},
|
||||
Element {
|
||||
id: 2,
|
||||
name: 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]
|
||||
},
|
||||
Element {
|
||||
id: 3,
|
||||
name: 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]
|
||||
}
|
||||
])
|
||||
};
|
||||
|
||||
view! {
|
||||
ul {
|
||||
Keyed(
|
||||
list=state.elements,
|
||||
view=|elt| {
|
||||
let name = elt.name.clone();
|
||||
let rep_components = elt.rep.iter().map(
|
||||
|u| View::from(div().children(u.to_string().replace("-", "\u{2212}")))
|
||||
).collect::<Vec<_>>();
|
||||
view! {
|
||||
li {
|
||||
div(class="elt-name") { (name) }
|
||||
div(class="elt-rep") { (rep_components) }
|
||||
}
|
||||
}
|
||||
},
|
||||
key=|elt| elt.id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
13
app-proto/sketch-outline/src/main.rs
Normal file
13
app-proto/sketch-outline/src/main.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use sycamore::prelude::*;
|
||||
|
||||
mod editor;
|
||||
|
||||
use editor::Editor;
|
||||
|
||||
fn main() {
|
||||
sycamore::render(|| {
|
||||
view! {
|
||||
Editor {}
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue