WIP: Clean up the outline view #16

Closed
Vectornaut wants to merge 29 commits from outline-cleanup into main
Showing only changes of commit bbeebe4464 - Show all commits

View File

@ -43,13 +43,9 @@ fn ConstraintOutlineItem(constraint_key: usize, element_key: usize) -> View {
constraint.args.0 constraint.args.0
}; };
let other_arg_label = assembly.elements.with(|elts| elts[other_arg].label.clone()); let other_arg_label = assembly.elements.with(|elts| elts[other_arg].label.clone());
let class = create_memo(move || { let class = constraint.rep_valid.map(
if constraint.rep_valid.get() { |&rep_valid| if rep_valid { "cst" } else { "cst invalid" }
"cst" );
} else {
"cst invalid"
}
});
view! { view! {
li(class=class.get()) { li(class=class.get()) {
input(r#type="checkbox", bind:checked=constraint.active) input(r#type="checkbox", bind:checked=constraint.active)
@ -64,13 +60,9 @@ fn ConstraintOutlineItem(constraint_key: usize, element_key: usize) -> View {
#[component(inline_props)] #[component(inline_props)]
fn ElementOutlineItem(key: usize, element: assembly::Element) -> View { fn ElementOutlineItem(key: usize, element: assembly::Element) -> View {
let state = use_context::<AppState>(); let state = use_context::<AppState>();
let class = create_memo(move || { let class = state.selection.map(
if state.selection.with(|sel| sel.contains(&key)) { move |sel| if sel.contains(&key) { "selected" } else { "" }
"selected" );
} else {
""
}
});
let label = element.label.clone(); let label = element.label.clone();
let rep_components = element.rep.iter().map(|u| { let rep_components = element.rep.iter().map(|u| {
let u_coord = format!("{:.3}", u).replace("-", "\u{2212}"); let u_coord = format!("{:.3}", u).replace("-", "\u{2212}");
@ -176,15 +168,16 @@ fn ElementOutlineItem(key: usize, element: assembly::Element) -> View {
// //
#[component] #[component]
pub fn Outline() -> View { pub fn Outline() -> View {
// sort the elements alphabetically by ID
let elements_sorted = create_memo(|| {
let state = use_context::<AppState>(); let state = use_context::<AppState>();
state.assembly.elements
.get_clone() // list the elements alphabetically by ID
let element_list = state.assembly.elements.map(
|elts| elts
.clone()
.into_iter() .into_iter()
.sorted_by_key(|(_, elt)| elt.id.clone()) .sorted_by_key(|(_, elt)| elt.id.clone())
.collect() .collect()
}); );
view! { view! {
ul( ul(
@ -195,7 +188,7 @@ pub fn Outline() -> View {
} }
) { ) {
Keyed( Keyed(
list=elements_sorted, list=element_list,
view=|(key, elt)| view! { view=|(key, elt)| view! {
ElementOutlineItem(key=key, element=elt) ElementOutlineItem(key=key, element=elt)
}, },