dyna3/app-proto/src/main.rs
Aaron Fenyes b02e682e15 Add space around = for Sycamore props
Also, add a trailing comma to a match arm in `outline.rs`.
2025-08-02 00:15:46 -07:00

69 lines
No EOL
1.5 KiB
Rust

mod assembly;
mod components;
mod engine;
mod specified;
#[cfg(test)]
mod tests;
use std::{collections::BTreeSet, rc::Rc};
use sycamore::prelude::*;
use assembly::{Assembly, Element};
use components::{
add_remove::AddRemove,
diagnostics::Diagnostics,
display::Display,
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 {}
Diagnostics {}
}
Display {}
}
});
}