AddRemove: make a button that adds constraints

This commit is contained in:
Aaron Fenyes 2024-09-26 15:02:51 -07:00
parent 4e3c86fb71
commit f5486fb0dd
3 changed files with 87 additions and 3 deletions

View File

@ -4,9 +4,11 @@ body {
background-color: #222; background-color: #222;
} }
/* outline */ /* sidebar */
#outline { #sidebar {
display: flex;
flex-direction: column;
float: left; float: left;
width: 450px; width: 450px;
height: 100vh; height: 100vh;
@ -15,6 +17,28 @@ body {
border-width: 0px 1px 0px 0px; border-width: 0px 1px 0px 0px;
border-style: solid; border-style: solid;
border-color: #555; border-color: #555;
}
/* add-remove */
#add-remove {
display: flex;
gap: 8px;
margin: 8px;
}
#add-remove > button {
width: 32px;
height: 32px;
font-size: large;
}
/* outline */
#outline {
flex-grow: 1;
margin: 0px;
padding: 0px;
overflow-y: scroll; overflow-y: scroll;
} }

View 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());
}
) { "🔗" }
}
}
}

View File

@ -1,3 +1,4 @@
mod add_remove;
mod assembly; mod assembly;
mod display; mod display;
mod outline; mod outline;
@ -6,6 +7,7 @@ use nalgebra::DVector;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use sycamore::prelude::*; use sycamore::prelude::*;
use add_remove::AddRemove;
use assembly::{Assembly, Constraint, Element}; use assembly::{Assembly, Constraint, Element};
use display::Display; use display::Display;
use outline::Outline; use outline::Outline;
@ -68,7 +70,10 @@ fn main() {
provide_context(state); provide_context(state);
view! { view! {
div(id="sidebar") {
AddRemove {}
Outline {} Outline {}
}
Display {} Display {}
} }
}); });