Clean up the outline view #19

Merged
glen merged 23 commits from outline-cleanup_on_main into main 2024-11-15 03:32:48 +00:00
Showing only changes of commit ec1911b889 - Show all commits

View File

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