forked from StudioInfinity/dyna3
55 lines
No EOL
1.9 KiB
Rust
55 lines
No EOL
1.9 KiB
Rust
use sycamore::prelude::*;
|
|
use web_sys::{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 |_| {
|
|
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 |_| {
|
|
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());
|
|
}
|
|
) { "🔗" }
|
|
}
|
|
}
|
|
} |