forked from StudioInfinity/dyna3
AddRemove: make a button that adds constraints
This commit is contained in:
parent
4e3c86fb71
commit
f5486fb0dd
3 changed files with 87 additions and 3 deletions
55
app-proto/full-interface/src/add_remove.rs
Normal file
55
app-proto/full-interface/src/add_remove.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use sycamore::prelude::*;
|
||||
use web_sys::{MouseEvent, console, wasm_bindgen::JsValue};
|
||||
|
||||
use crate::AppState;
|
||||
use crate::Constraint;
|
||||
|
||||
#[component]
|
||||
pub fn AddRemove() -> View {
|
||||
let state = use_context::<AppState>();
|
||||
|
||||
view! {
|
||||
div(id="add-remove") {
|
||||
button(
|
||||
on:click=move |event: MouseEvent| {
|
||||
console::log_1(&JsValue::from("constraints:"));
|
||||
state.assembly.constraints.with(|csts| {
|
||||
for (_, cst) in csts.into_iter() {
|
||||
console::log_4(
|
||||
&JsValue::from(cst.args.0),
|
||||
&JsValue::from(cst.args.1),
|
||||
&JsValue::from(":"),
|
||||
&JsValue::from(cst.rep)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
) { "+" }
|
||||
button(
|
||||
disabled={
|
||||
state.selection.with(|sel| sel.len() != 2)
|
||||
},
|
||||
on:click=move |event: MouseEvent| {
|
||||
let args = state.selection.with(
|
||||
|sel| {
|
||||
let arg_vec: Vec<_> = sel.into_iter().collect();
|
||||
(arg_vec[0].clone(), arg_vec[1].clone())
|
||||
}
|
||||
);
|
||||
console::log_5(
|
||||
&JsValue::from("add constraint"),
|
||||
&JsValue::from(args.0),
|
||||
&JsValue::from(args.1),
|
||||
&JsValue::from(":"),
|
||||
&JsValue::from(0.0)
|
||||
);
|
||||
state.assembly.insert_constraint(Constraint {
|
||||
args: args,
|
||||
rep: 0.0
|
||||
});
|
||||
state.selection.update(|sel| sel.clear());
|
||||
}
|
||||
) { "🔗" }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue