2025-11-28 00:09:00 -07:00
|
|
|
mod app;
|
|
|
|
|
mod windows;
|
|
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
2025-11-29 13:15:09 -07:00
|
|
|
use crate::{app::windows::WindowWrapper, auth::Auth, config::Config, flowchart::FlowChart};
|
2025-11-28 00:09:00 -07:00
|
|
|
pub use app::TemplateApp;
|
|
|
|
|
use egui_tiles::{TileId, Tree};
|
|
|
|
|
|
|
|
|
|
#[derive(Default, serde::Deserialize, serde::Serialize)]
|
2025-11-29 13:15:09 -07:00
|
|
|
pub struct AppState {
|
|
|
|
|
pub auth: Auth,
|
|
|
|
|
|
2025-11-28 00:09:00 -07:00
|
|
|
pub open_windows: HashMap<AppWindow, TileId>,
|
|
|
|
|
|
|
|
|
|
pub flowchart: FlowChart,
|
|
|
|
|
pub config: Config,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AppState {
|
|
|
|
|
pub fn labels(&mut self, tree: &mut Tree<WindowWrapper>, ui: &mut egui::Ui) {
|
|
|
|
|
for (i, (key, name)) in (vec![
|
|
|
|
|
(AppWindow::Flowchart, "Flowchart"),
|
|
|
|
|
(AppWindow::Config, "Config"),
|
|
|
|
|
])
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
{
|
|
|
|
|
let enabled = self.open_windows.contains_key(&key);
|
|
|
|
|
|
|
|
|
|
if ui.selectable_label(enabled, *name).clicked() {
|
2025-11-28 18:39:14 -07:00
|
|
|
if enabled {
|
|
|
|
|
let tid = *self.open_windows.get(&key).unwrap();
|
|
|
|
|
tree.remove_recursively(tid);
|
|
|
|
|
tree.tiles.remove(tid);
|
|
|
|
|
self.open_windows.remove(&key);
|
|
|
|
|
|
|
|
|
|
// if self.open_windows.is_empty()
|
|
|
|
|
} else {
|
|
|
|
|
let tid = tree.tiles.insert_pane(WindowWrapper {
|
|
|
|
|
nr: i + 1,
|
|
|
|
|
window: *key,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
match self.open_windows.len() {
|
|
|
|
|
0 => {
|
|
|
|
|
tree.root = Some(tid);
|
|
|
|
|
}
|
|
|
|
|
1 => {
|
|
|
|
|
let old_root = tree.root.unwrap();
|
|
|
|
|
let tab_id = tree.tiles.insert_tab_tile(vec![old_root, tid]);
|
|
|
|
|
tree.root = Some(tab_id);
|
|
|
|
|
tree.make_active(|t, _| t == tid);
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
let root = tree.root().unwrap();
|
|
|
|
|
let n = tree.tiles.get_container(root).unwrap().num_children();
|
|
|
|
|
tree.move_tile_to_container(tid, tree.root.unwrap().clone(), n, true);
|
|
|
|
|
}
|
2025-11-28 00:09:00 -07:00
|
|
|
}
|
2025-11-28 18:39:14 -07:00
|
|
|
self.open_windows.insert(key.clone(), tid);
|
2025-11-28 00:09:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, serde::Deserialize, serde::Serialize, PartialEq, Eq, Hash)]
|
2025-11-29 13:15:09 -07:00
|
|
|
pub enum AppWindow {
|
2025-11-28 00:09:00 -07:00
|
|
|
Flowchart,
|
|
|
|
|
Config,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AppWindow {
|
|
|
|
|
fn update(&self, state: &mut AppState, ui: &mut egui::Ui) {
|
|
|
|
|
match self {
|
|
|
|
|
AppWindow::Flowchart => state.flowchart.paint(ui),
|
2025-11-29 13:15:09 -07:00
|
|
|
AppWindow::Config => state.config.update(&mut state.auth, ui),
|
2025-11-28 00:09:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|