Skip to main content

custom_theme/
custom_theme.rs

1//! Custom Theme Example — FlashKraft GUI
2//!
3//! Launches the FlashKraft desktop application with a pre-selected theme,
4//! demonstrating the full theme system:
5//!
6//! - 21 built-in Iced themes (dark + light variants)
7//! - Runtime theme switching via the 🎨 button
8//! - Theme preference persisted across sessions via `sled`
9//! - Every UI component — buttons, progress bars, panels — adapts instantly
10//!
11//! # Run
12//!
13//! ```bash
14//! cargo run -p flashkraft-gui --example custom_theme
15//! ```
16
17use flashkraft_gui::{FlashKraft, Message};
18use iced::{Settings, Task, Theme};
19
20fn main() -> iced::Result {
21    println!("╔══════════════════════════════════════════════╗");
22    println!("║   FlashKraft GUI — Custom Theme Example      ║");
23    println!("╚══════════════════════════════════════════════╝");
24    println!();
25    println!("Launching with the Tokyo Night theme pre-selected.");
26    println!();
27    println!("Available dark themes:");
28    println!("  • Dark (default)      • Dracula");
29    println!("  • Nord                • Solarized Dark");
30    println!("  • Gruvbox Dark        • Catppuccin Mocha");
31    println!("  • Tokyo Night         • Kanagawa Wave");
32    println!("  • Moonfly             • Nightfly");
33    println!("  • Oxocarbon");
34    println!();
35    println!("Available light themes:");
36    println!("  • Light               • Solarized Light");
37    println!("  • Gruvbox Light       • Catppuccin Latte");
38    println!("  • Tokyo Night Light   • Kanagawa Lotus");
39    println!();
40    println!("How to switch themes at runtime:");
41    println!("  1. Click the [🎨] button in the top-right corner");
42    println!("  2. Select any theme from the picker");
43    println!("  3. The entire UI updates instantly");
44    println!("  4. Your choice is saved and restored on next launch");
45    println!();
46
47    // Build initial state pre-configured with Tokyo Night.
48    let mut initial_state = FlashKraft::new();
49    initial_state.theme = Theme::TokyoNight;
50
51    // Persist the pre-selected theme so it survives a restart.
52    if let Some(storage) = &initial_state.storage {
53        let _ = storage.save_theme(&Theme::TokyoNight);
54    }
55
56    iced::application(
57        "FlashKraft — Custom Theme Demo",
58        FlashKraft::update,
59        FlashKraft::view,
60    )
61    .subscription(FlashKraft::subscription)
62    .theme(|state: &FlashKraft| state.theme.clone())
63    .settings(Settings {
64        fonts: vec![iced_fonts::BOOTSTRAP_FONT_BYTES.into()],
65        ..Default::default()
66    })
67    .window(iced::window::Settings {
68        size: iced::Size::new(1300.0, 700.0),
69        resizable: false,
70        decorations: true,
71        ..Default::default()
72    })
73    .run_with(move || {
74        let load_drives = Task::perform(
75            flashkraft_core::commands::load_drives(),
76            Message::DrivesRefreshed,
77        );
78        (initial_state, load_drives)
79    })
80}