Clean up the outline view #19
@ -9,7 +9,7 @@ use web_sys::{
|
|||||||
wasm_bindgen::JsCast
|
wasm_bindgen::JsCast
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{AppState, assembly::Constraint};
|
use crate::{AppState, assembly::{Constraint, ConstraintKey, ElementKey}};
|
||||||
|
|
||||||
// an editable view of the Lorentz product representing a constraint
|
// an editable view of the Lorentz product representing a constraint
|
||||||
#[component(inline_props)]
|
#[component(inline_props)]
|
||||||
@ -32,6 +32,27 @@ fn LorentzProductInput(constraint: Constraint) -> View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a list item that shows a constraint in an outline view of an element
|
||||||
|
#[component(inline_props)]
|
||||||
|
fn ConstraintOutlineItem(constraint_key: ConstraintKey, element_key: ElementKey) -> View {
|
||||||
|
let state = use_context::<AppState>();
|
||||||
|
let assembly = &state.assembly;
|
||||||
|
let constraint = assembly.constraints.with(|csts| csts[constraint_key].clone());
|
||||||
|
let other_subject = if constraint.subjects.0 == element_key {
|
||||||
|
constraint.subjects.1
|
||||||
|
} else {
|
||||||
|
constraint.subjects.0
|
||||||
|
};
|
||||||
|
let other_subject_label = assembly.elements.with(|elts| elts[other_subject].label.clone());
|
||||||
|
view! {
|
||||||
|
li(class="cst") {
|
||||||
|
input(r#type="checkbox", bind:checked=constraint.active)
|
||||||
|
div(class="cst-label") { (other_subject_label) }
|
||||||
|
LorentzProductInput(constraint=constraint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// a component that lists the elements of the current assembly, showing the
|
// a component that lists the elements of the current assembly, showing the
|
||||||
// constraints on each element as a collapsible sub-list. its implementation
|
// constraints on each element as a collapsible sub-list. its implementation
|
||||||
// is based on Kate Morley's HTML + CSS tree views:
|
// is based on Kate Morley's HTML + CSS tree views:
|
||||||
@ -150,25 +171,13 @@ pub fn Outline() -> View {
|
|||||||
ul(class="constraints") {
|
ul(class="constraints") {
|
||||||
Keyed(
|
Keyed(
|
||||||
list=elt.constraints.into_iter().collect::<Vec<_>>(),
|
list=elt.constraints.into_iter().collect::<Vec<_>>(),
|
||||||
view=move |c_key| {
|
view=move |cst_key| view! {
|
||||||
let c_state = use_context::<AppState>();
|
ConstraintOutlineItem(
|
||||||
let assembly = &c_state.assembly;
|
constraint_key=cst_key,
|
||||||
let cst = assembly.constraints.with(|csts| csts[c_key].clone());
|
element_key=key
|
||||||
let other_arg = if cst.subjects.0 == key {
|
)
|
||||||
cst.subjects.1
|
|
||||||
} else {
|
|
||||||
cst.subjects.0
|
|
||||||
};
|
|
||||||
let other_arg_label = assembly.elements.with(|elts| elts[other_arg].label.clone());
|
|
||||||
view! {
|
|
||||||
li(class="cst") {
|
|
||||||
input(r#type="checkbox", bind:checked=cst.active)
|
|
||||||
div(class="cst-label") { (other_arg_label) }
|
|
||||||
LorentzProductInput(constraint=cst)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
key=|c_key| c_key.clone()
|
key=|cst_key| cst_key.clone()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user