From e5f4d523f90161a4615c5d4c51d83cb6e2a6cb1c Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Tue, 29 Oct 2024 13:46:15 -0700 Subject: [PATCH] Update the realization when a constraint is activated Sycamore probably has a better way to do this, but this way works for now. --- app-proto/src/add_remove.rs | 10 +++++++++- app-proto/src/assembly.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app-proto/src/add_remove.rs b/app-proto/src/add_remove.rs index 7066089..00b63f8 100644 --- a/app-proto/src/add_remove.rs +++ b/app-proto/src/add_remove.rs @@ -214,10 +214,11 @@ pub fn AddRemove() -> View { (arg_vec[0].clone(), arg_vec[1].clone()) } ); + let active = create_signal(true); state.assembly.insert_constraint(Constraint { args: args, rep: 0.0, - active: create_signal(true) + active: active }); state.assembly.realize(); state.selection.update(|sel| sel.clear()); @@ -236,6 +237,13 @@ pub fn AddRemove() -> View { ); } }); + + // make constraint activation trigger a realization update + create_effect(move || { + if active.get() { + state.assembly.realize(); + } + }); } ) { "🔗" } select(bind:value=assembly_name) { /* DEBUG */ diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index 228357e..648d0ef 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -97,7 +97,7 @@ impl Assembly { self.elements.update(|elts| { elts[args.0].constraints.insert(key); elts[args.1].constraints.insert(key); - }) + }); } // --- realization --- @@ -116,10 +116,12 @@ impl Assembly { let mut gram_to_be = PartialMatrix::new(); self.constraints.with_untracked(|csts| { for (_, cst) in csts { - let args = cst.args; - let row = elts[args.0].index; - let col = elts[args.1].index; - gram_to_be.push_sym(row, col, cst.rep); + if cst.active.get_untracked() { + let args = cst.args; + let row = elts[args.0].index; + let col = elts[args.1].index; + gram_to_be.push_sym(row, col, cst.rep); + } } });