feat: Points (#82)

Replaces the former sole Element entity by two, Sphere and Point, both implementing an Element trait. Adds Point display, uses the former Element display for Sphere. Adds a new "canned" configuration, and the ability to add, select, and nudge Point entities.

Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo>
Reviewed-on: StudioInfinity/dyna3#82
Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net>
Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
This commit is contained in:
Vectornaut 2025-05-01 19:25:13 +00:00 committed by Glen Whitney
parent 360ce12d8b
commit a2478febc1
9 changed files with 815 additions and 330 deletions

View file

@ -9,9 +9,10 @@ use web_sys::{
use crate::{
AppState,
assembly,
assembly::{
Element,
ElementKey,
ElementRc,
HalfCurvatureRegulator,
InversiveDistanceRegulator,
Regulator,
@ -103,7 +104,7 @@ impl OutlineItem for InversiveDistanceRegulator {
self.subjects[0]
};
let other_subject_label = state.assembly.elements.with(
|elts| elts[other_subject].label.clone()
|elts| elts[other_subject].label().clone()
);
view! {
li(class="regulator") {
@ -141,14 +142,15 @@ fn RegulatorOutlineItem(regulator_key: RegulatorKey, element_key: ElementKey) ->
// a list item that shows an element in an outline view of an assembly
#[component(inline_props)]
fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
fn ElementOutlineItem(key: ElementKey, element: Rc<dyn Element>) -> View {
let state = use_context::<AppState>();
let class = state.selection.map(
move |sel| if sel.contains(&key) { "selected" } else { "" }
);
let label = element.label.clone();
let label = element.label().clone();
let representation = element.representation().clone();
let rep_components = move || {
element.representation.with(
representation.with(
|rep| rep.iter().map(
|u| {
let u_str = format!("{:.3}", u).replace("-", "\u{2212}");
@ -157,8 +159,8 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
).collect::<Vec<_>>()
)
};
let regulated = element.regulators.map(|regs| regs.len() > 0);
let regulator_list = element.regulators.map(
let regulated = element.regulators().map(|regs| regs.len() > 0);
let regulator_list = element.regulators().map(
move |elt_reg_keys| elt_reg_keys
.clone()
.into_iter()
@ -261,7 +263,8 @@ pub fn Outline() -> View {
|elts| elts
.clone()
.into_iter()
.sorted_by_key(|(_, elt)| elt.id.clone())
.sorted_by_key(|(_, elt)| elt.id().clone())
.map(|(key, elt)| (key, ElementRc(elt)))
.collect()
);
@ -275,10 +278,10 @@ pub fn Outline() -> View {
) {
Keyed(
list=element_list,
view=|(key, elt)| view! {
view=|(key, ElementRc(elt))| view! {
ElementOutlineItem(key=key, element=elt)
},
key=|(_, elt)| elt.serial
key=|(_, ElementRc(elt))| elt.serial()
)
}
}