Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-app/examples/nav_app.rs

//! `cargo run -p facett-app --example nav_app`
//!
//! The nav backbone live: a sidebar drives a router; the content shows
//! back/forward + a breadcrumb + the routed body. Pure egui on the glow backend.

use eframe::egui;
use facett_app::{Dropdown, NavItem, NavModel, NavShell};
use facett_core::Facet;

fn model() -> NavModel {
    NavModel::new([
        NavItem::new("home", "Home").icon("🏠"),
        NavItem::new("data", "Data").icon("🗃").children([
            NavItem::new("data.grid", "Grid").route("grid").badge("12k"),
            NavItem::new("data.table", "Table").route("table"),
            NavItem::new("data.iceberg", "Iceberg").route("iceberg"),
        ]),
        NavItem::new("viz", "Visualise").icon("📊").children([
            NavItem::new("viz.graph3d", "Graph 3D").route("graph3d"),
            NavItem::new("viz.map", "Map").route("map"),
        ]),
        NavItem::new("settings", "Settings").icon("⚙"),
        NavItem::new("admin", "Admin (locked)").disabled(),
    ])
}

struct App {
    shell: NavShell,
}

impl Default for App {
    fn default() -> Self {
        let theme = Dropdown::new("theme")
            .options([("dark", "Windows Dark"), ("light", "Windows Light"), ("vinter", "Skade Vinter")])
            .with_selected("dark")
            .placeholder("Theme");
        let shell = NavShell::new("nav", model())
            .with_body("home", "Welcome to the facett app shell — pick something on the left.")
            .with_body("grid", "The Arrow grid would render here (facett-grid).")
            .with_body("table", "The data table would render here (facett-table).")
            .with_body("graph3d", "The 3D graph cloud would render here (facett-graph3d).")
            .with_body("map", "The map would render here (facett-map).")
            .with_body("settings", "App settings — the Theme picker below is a facett-app Dropdown.")
            .with_route_dropdown("settings", "Theme", theme);
        Self { shell }
    }
}

impl eframe::App for App {
    fn ui(&mut self, root: &mut egui::Ui, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(root, |ui| {
            self.shell.ui(ui);
        });
    }
}

fn main() -> eframe::Result {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size(egui::Vec2::new(900.0, 620.0)),
        ..Default::default()
    };
    eframe::run_native("facett-app · nav_app", options, Box::new(|_cc| Ok(Box::<App>::default())))
}