Skip to main content

kyu_visualizer/
lib.rs

1//! kyu-viz library: shared modules + `launch` entry point.
2//!
3//! Exposes a single `launch(db)` function so that examples and the default
4//! binary can each seed the database differently before opening the window.
5
6#![allow(dead_code)]
7
8pub mod app;
9pub mod canvas;
10pub mod graph;
11pub mod state;
12pub mod theme;
13pub mod transitions;
14pub mod ui;
15
16use std::sync::Arc;
17
18use blinc_app::WindowConfig;
19use blinc_app::windowed::WindowedApp;
20use kyu_api::Database;
21
22/// Open the KyuGraph visualizer window with a pre-configured database.
23///
24/// Any tables already in `db` will be loaded into the canvas on startup.
25/// Extensions must be registered on `db` before calling this function.
26pub fn launch(db: Database) -> Result<(), Box<dyn std::error::Error>> {
27    let config = WindowConfig {
28        title: "KyuGraph Visualizer".to_string(),
29        width: 1280,
30        height: 800,
31        ..Default::default()
32    };
33
34    let db = Arc::new(db);
35    let initial = app::load_initial_data(&db);
36
37    let mut css_loaded = false;
38    WindowedApp::run(config, move |ctx| {
39        if !css_loaded {
40            ctx.add_css(include_str!("../style.css"));
41            css_loaded = true;
42        }
43        let db = db.clone();
44        app::build_ui(ctx, db, &initial)
45    })?;
46    Ok(())
47}