dyna3/app-proto/src/main.rs
Vectornaut 2adf4669f4 Refactor: Use pointers to refer to elements and regulators (#84)
Previously, dyna3 used storage keys to refer to elements, necessitating passing around element containers to various functions so that they could access the relevant elements. These storage keys have been replaced with reference-counted pointers, used for tasks like these:

- Specifying the subjects of regulators.
- Collecting the regulators each element is subject to
- Handling selection.
- Creating interface components.

Also, systematizes the handling of serial numbers for entities, through a Serial trait.
And updates to rust 1.86 and institutes explicit checking of the rust version.

Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo>
Reviewed-on: StudioInfinity/dyna3#84
Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net>
Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
2025-05-06 19:17:30 +00:00

67 lines
No EOL
1.5 KiB
Rust

mod add_remove;
mod assembly;
mod display;
mod engine;
mod outline;
mod specified;
#[cfg(test)]
mod tests;
use std::{collections::BTreeSet, rc::Rc};
use sycamore::prelude::*;
use add_remove::AddRemove;
use assembly::{Assembly, Element};
use display::Display;
use outline::Outline;
#[derive(Clone)]
struct AppState {
assembly: Assembly,
selection: Signal<BTreeSet<Rc<dyn Element>>>
}
impl AppState {
fn new() -> AppState {
AppState {
assembly: Assembly::new(),
selection: create_signal(BTreeSet::default())
}
}
// in single-selection mode, select the given element. in multiple-selection
// mode, toggle whether the given element is selected
fn select(&self, element: &Rc<dyn Element>, multi: bool) {
if multi {
self.selection.update(|sel| {
if !sel.remove(element) {
sel.insert(element.clone());
}
});
} else {
self.selection.update(|sel| {
sel.clear();
sel.insert(element.clone());
});
}
}
}
fn main() {
// set the console error panic hook
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
sycamore::render(|| {
provide_context(AppState::new());
view! {
div(id="sidebar") {
AddRemove {}
Outline {}
}
Display {}
}
});
}