WIP: Clean up the outline view #16

Closed
Vectornaut wants to merge 29 commits from outline-cleanup into main
Showing only changes of commit 7f595ff27a - Show all commits

View File

@ -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: usize, element_key: usize) -> View {
let state = use_context::<AppState>();
let assembly = &state.assembly;
let constraint = assembly.constraints.with(|csts| csts[constraint_key].clone());
let other_arg = if constraint.args.0 == element_key {
constraint.args.1
} else {
constraint.args.0
};
let other_arg_label = assembly.elements.with(|elts| elts[other_arg].label.clone());
view! {
li(class="cst") {
input(r#type="checkbox", bind:checked=constraint.active)
div(class="cst-label") { (other_arg_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: usize| { 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.args.0 == key { )
cst.args.1
} else {
cst.args.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()
) )
} }
} }