From 8daef5f71e07f38892b0cdfd47dda1d7c711ca1f Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Fri, 15 Nov 2024 17:15:36 -0800 Subject: [PATCH] Key element outline items by assembly Introduce an assembly serial number, which increments when we load a new assembly. Include it in each element outline item's diff key. --- app-proto/src/add_remove.rs | 3 +++ app-proto/src/main.rs | 2 ++ app-proto/src/outline.rs | 18 +++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app-proto/src/add_remove.rs b/app-proto/src/add_remove.rs index ba02e65..f21c2ab 100644 --- a/app-proto/src/add_remove.rs +++ b/app-proto/src/add_remove.rs @@ -148,6 +148,9 @@ pub fn AddRemove() -> View { assembly.elements_by_id.update(|elts_by_id| elts_by_id.clear()); state.selection.update(|sel| sel.clear()); + // increment assembly serial number + state.assembly_serial.set_fn_silent(|serial| serial.wrapping_add(1)); + // load assembly match name.as_str() { "general" => load_gen_assemb(assembly), diff --git a/app-proto/src/main.rs b/app-proto/src/main.rs index 897f9d4..8e8e4f0 100644 --- a/app-proto/src/main.rs +++ b/app-proto/src/main.rs @@ -15,6 +15,7 @@ use outline::Outline; #[derive(Clone)] struct AppState { assembly: Assembly, + assembly_serial: Signal, selection: Signal> } @@ -22,6 +23,7 @@ impl AppState { fn new() -> AppState { AppState { assembly: Assembly::new(), + assembly_serial: create_signal(1), selection: create_signal(FxHashSet::default()) } } diff --git a/app-proto/src/outline.rs b/app-proto/src/outline.rs index ee1603f..39247fa 100644 --- a/app-proto/src/outline.rs +++ b/app-proto/src/outline.rs @@ -180,11 +180,15 @@ pub fn Outline() -> View { // 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() + move |elts| { + let asm_serial = state.assembly_serial.get_untracked(); + elts + .clone() + .into_iter() + .sorted_by_key(|(_, elt)| elt.id.clone()) + .map(|(key, elt)| (asm_serial, key, elt)) + .collect() + } ); view! { @@ -197,10 +201,10 @@ pub fn Outline() -> View { ) { Keyed( list=element_list, - view=|(key, elt)| view! { + view=|(_, key, elt)| view! { ElementOutlineItem(key=key, element=elt) }, - key=|(key, _)| key.clone() + key=|(asm_serial, key, _)| (asm_serial.clone(), key.clone()) ) } } -- 2.34.1