App: store constraints

Draft listing of constraints in outline view.
This commit is contained in:
Aaron Fenyes 2024-09-22 14:05:40 -07:00
parent 147e275823
commit 050e2373a6
4 changed files with 89 additions and 51 deletions

View File

@ -7,7 +7,7 @@ body {
/* outline */ /* outline */
ul { #outline {
float: left; float: left;
width: 450px; width: 450px;
height: 750px; height: 750px;
@ -19,32 +19,35 @@ ul {
} }
li { li {
display: flex;
padding: 3px;
list-style-type: none; list-style-type: none;
background-color: #444;
border-radius: 8px;
}
li.selected {
color: #fff;
background-color: #666;
} }
li:not(:last-child) { li:not(:last-child) {
margin-bottom: 8px; margin-bottom: 8px;
} }
li > .elt-label { .elt {
display: flex;
padding: 3px;
background-color: #444;
border-radius: 8px;
}
.elt.selected {
color: #fff;
background-color: #666;
}
.elt > .elt-label {
flex-grow: 1; flex-grow: 1;
padding: 2px 0px 2px 4px; padding: 2px 0px 2px 4px;
} }
li > .elt-rep { .elt > .elt-rep {
display: flex; display: flex;
} }
li > .elt-rep > div { .elt > .elt-rep > div {
padding: 2px; padding: 2px;
margin-left: 3px; margin-left: 3px;
text-align: center; text-align: center;
@ -52,18 +55,26 @@ li > .elt-rep > div {
background-color: #333; background-color: #333;
} }
li.selected > .elt-rep > div { .elt.selected > .elt-rep > div {
background-color: #555; background-color: #555;
} }
li > .elt-rep > div:first-child { .elt-rep > div:first-child {
border-radius: 6px 0px 0px 6px; border-radius: 6px 0px 0px 6px;
} }
li > .elt-rep > div:last-child { .elt-rep > div:last-child {
border-radius: 0px 6px 6px 0px; border-radius: 0px 6px 6px 0px;
} }
.constraints > li {
margin-top: 4px;
margin-bottom: 4px;
padding: 5px;
background-color: #444;
border-radius: 8px;
}
/* display */ /* display */
canvas { canvas {

View File

@ -1,4 +1,5 @@
use nalgebra::DVector; use nalgebra::DVector;
use rustc_hash::FxHashSet;
use slab::Slab; use slab::Slab;
use sycamore::reactive::Signal; use sycamore::reactive::Signal;
@ -7,11 +8,18 @@ pub struct Element {
pub id: String, pub id: String,
pub label: String, pub label: String,
pub color: [f32; 3], pub color: [f32; 3],
pub rep: DVector<f64> pub rep: DVector<f64>,
pub constraints: FxHashSet<usize>
}
pub struct Constraint {
pub args: (usize, usize),
pub rep: f64
} }
// a complete, view-independent description of an assembly // a complete, view-independent description of an assembly
#[derive(Clone)] #[derive(Clone)]
pub struct Assembly { pub struct Assembly {
pub elements: Signal<Slab<Element>> pub elements: Signal<Slab<Element>>,
pub constraints: Signal<Slab<Constraint>>
} }

View File

@ -21,7 +21,8 @@ fn main() {
sycamore::render(|| { sycamore::render(|| {
let state = AppState { let state = AppState {
assembly: Assembly { assembly: Assembly {
elements: create_signal(Slab::new()) elements: create_signal(Slab::new()),
constraints: create_signal(Slab::new())
}, },
selection: create_signal(FxHashSet::default()) selection: create_signal(FxHashSet::default())
}; };
@ -31,7 +32,13 @@ fn main() {
id: String::from("wing_a"), id: String::from("wing_a"),
label: String::from("Wing A"), label: String::from("Wing A"),
color: [1.00_f32, 0.25_f32, 0.00_f32], color: [1.00_f32, 0.25_f32, 0.00_f32],
rep: DVector::<f64>::from_column_slice(&[0.5, 0.5, 0.0, 0.5, -0.25]) rep: DVector::<f64>::from_column_slice(&[0.5, 0.5, 0.0, 0.5, -0.25]),
constraints: {
let mut set = FxHashSet::default();
set.insert(1);
set.insert(2);
set
}
} }
) )
); );
@ -41,7 +48,8 @@ fn main() {
id: String::from("wing_b"), id: String::from("wing_b"),
label: String::from("Wing B"), label: String::from("Wing B"),
color: [0.00_f32, 0.25_f32, 1.00_f32], color: [0.00_f32, 0.25_f32, 1.00_f32],
rep: DVector::<f64>::from_column_slice(&[-0.5, -0.5, 0.0, 0.5, -0.25]) rep: DVector::<f64>::from_column_slice(&[-0.5, -0.5, 0.0, 0.5, -0.25]),
constraints: FxHashSet::default()
}, },
) )
); );
@ -51,7 +59,8 @@ fn main() {
id: String::from("central"), id: String::from("central"),
label: String::from("Central"), label: String::from("Central"),
color: [0.75_f32, 0.75_f32, 0.75_f32], color: [0.75_f32, 0.75_f32, 0.75_f32],
rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.4, -0.625]) rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.4, -0.625]),
constraints: FxHashSet::default()
} }
) )
); );

View File

@ -18,6 +18,7 @@ pub fn Outline() -> View {
view! { view! {
ul( ul(
id="outline",
on:click={ on:click={
let state = use_context::<AppState>(); let state = use_context::<AppState>();
move |_| state.selection.update(|sel| sel.clear()) move |_| state.selection.update(|sel| sel.clear())
@ -30,9 +31,9 @@ pub fn Outline() -> View {
let class = create_memo({ let class = create_memo({
move || { move || {
if state.selection.with(|sel| sel.contains(&key)) { if state.selection.with(|sel| sel.contains(&key)) {
"selected" "elt selected"
} else { } else {
"" "elt"
} }
} }
}); });
@ -44,7 +45,8 @@ pub fn Outline() -> View {
view! { view! {
/* [TO DO] switch to integer-valued parameters whenever /* [TO DO] switch to integer-valued parameters whenever
that becomes possible again */ that becomes possible again */
li( li {
div(
class=class.get(), class=class.get(),
tabindex="0", tabindex="0",
on:click={ on:click={
@ -87,6 +89,14 @@ pub fn Outline() -> View {
div(class="elt-label") { (label) } div(class="elt-label") { (label) }
div(class="elt-rep") { (rep_components) } div(class="elt-rep") { (rep_components) }
} }
ul(class="constraints") {
Keyed(
list=elt.constraints.into_iter().collect::<Vec<_>>(),
view=|c_key: usize| view! { li { (c_key.to_string()) } },
key=|c_key| c_key.clone()
)
}
}
} }
}, },
key=|(key, _)| key.clone() key=|(key, _)| key.clone()