WIP: Clean up the outline view #16

Closed
Vectornaut wants to merge 29 commits from outline-cleanup into main
3 changed files with 63 additions and 39 deletions
Showing only changes of commit 5ce5f855d5 - Show all commits

View File

@ -12,7 +12,7 @@ pub struct Element {
pub id: String,
pub label: String,
pub color: [f32; 3],
pub rep: DVector<f64>,
pub rep: Signal<DVector<f64>>,
pub constraints: Signal<BTreeSet<usize>>,
// internal properties, not reflected in any view
@ -30,7 +30,7 @@ impl Element {
id: id,
label: label,
color: color,
rep: rep,
rep: create_signal(rep),
constraints: create_signal(BTreeSet::default()),
index: 0
}
@ -151,7 +151,7 @@ impl Assembly {
for (_, elt) in elts {
let index = elt.index;
gram_to_be.push_sym(index, index, 1.0);
guess_to_be.set_column(index, &elt.rep);
guess_to_be.set_column(index, &elt.rep.get_clone());
}
(gram_to_be, guess_to_be)
@ -193,11 +193,11 @@ impl Assembly {
if success {
// read out the solution
self.elements.update(|elts| {
for (_, elt) in elts.iter_mut() {
elt.rep.set_column(0, &config.column(elt.index));
}
});
for (_, elt) in self.elements.get_clone() {
elt.rep.update(
|rep| rep.set_column(0, &config.column(elt.index))
);
}
}
}
}

View File

@ -103,7 +103,11 @@ pub fn Display() -> View {
// change listener
let scene_changed = create_signal(true);
create_effect(move || {
state.assembly.elements.track();
state.assembly.elements.with(|elts| {
for (_, elt) in elts {
elt.rep.track();
}
});
state.selection.track();
scene_changed.set(true);
});
@ -295,23 +299,40 @@ pub fn Display() -> View {
let assembly_to_world = &location * &orientation;
// get the assembly
let elements = state.assembly.elements.get_clone();
let element_iter = (&elements).into_iter();
let reps_world: Vec<_> = element_iter.clone().map(|(_, elt)| &assembly_to_world * &elt.rep).collect();
let colors: Vec<_> = element_iter.clone().map(|(key, elt)|
let (
elt_cnt,
reps_world,
colors,
highlights
) = state.assembly.elements.with(|elts| {
(
// number of elements
elts.len() as i32,
// representation vectors in world coordinates
elts.iter().map(
|(_, elt)| elt.rep.with(|rep| &assembly_to_world * rep)
).collect::<Vec<_>>(),
// colors
elts.iter().map(|(key, elt)| {
if state.selection.with(|sel| sel.contains(&key)) {
elt.color.map(|ch| 0.2 + 0.8*ch)
} else {
elt.color
}
).collect();
let highlights: Vec<_> = element_iter.map(|(key, _)|
}).collect::<Vec<_>>(),
// highlight levels
elts.iter().map(|(key, _)| {
if state.selection.with(|sel| sel.contains(&key)) {
1.0_f32
} else {
HIGHLIGHT
}
).collect();
}).collect::<Vec<_>>()
)
});
// set the resolution
let width = canvas.width() as f32;
@ -320,7 +341,7 @@ pub fn Display() -> View {
ctx.uniform1f(shortdim_loc.as_ref(), width.min(height));
// pass the assembly
ctx.uniform1i(sphere_cnt_loc.as_ref(), elements.len() as i32);
ctx.uniform1i(sphere_cnt_loc.as_ref(), elt_cnt);
for n in 0..reps_world.len() {
let v = &reps_world[n];
ctx.uniform3f(

View File

@ -1,5 +1,5 @@
use itertools::Itertools;
use sycamore::{prelude::*, web::tags::div};
use sycamore::prelude::*;
use web_sys::{
Event,
HtmlInputElement,
@ -64,10 +64,11 @@ fn ElementOutlineItem(key: usize, element: assembly::Element) -> View {
move |sel| if sel.contains(&key) { "selected" } else { "" }
);
let label = element.label.clone();
let rep_components = element.rep.iter().map(|u| {
let u_coord = format!("{:.3}", u).replace("-", "\u{2212}");
View::from(div().children(u_coord))
}).collect::<Vec<_>>();
let rep_components = element.rep.map(
|rep| rep.iter().map(
|u| format!("{:.3}", u).replace("-", "\u{2212}")
).collect()
);
let constrained = element.constraints.map(|csts| csts.len() > 0);
let constraint_list = element.constraints.map(
|csts| csts.clone().into_iter().collect()
@ -139,7 +140,14 @@ fn ElementOutlineItem(key: usize, element: assembly::Element) -> View {
}
) {
div(class="elt-label") { (label) }
div(class="elt-rep") { (rep_components) }
div(class="elt-rep") {
Indexed(
list=rep_components,
view=|coord_str| view! {
div { (coord_str) }
}
)
}
div(class="status")
}
}
@ -192,12 +200,7 @@ pub fn Outline() -> View {
view=|(key, elt)| view! {
ElementOutlineItem(key=key, element=elt)
},
key=|(key, elt)| (
key.clone(),
elt.id.clone(),
elt.label.clone(),
elt.rep.into_iter().map(|u| u.to_bits()).collect::<Vec<_>>()
)
key=|(key, _)| key.clone()
)
}
}