1use ash::{
2 extensions::khr::{Surface, Swapchain},
3 vk, Device, Entry, Instance,
4};
5use egui_winit::winit;
6use std::ffi::CString;
7
8#[cfg(feature = "persistence")]
9use crate::storage;
10use crate::{
11 event,
12 renderer::{EguiCommand, ImageRegistry},
13 Allocator, ExitSignal,
14};
15
16#[derive(Debug, PartialEq, Eq, Clone, Copy)]
18pub enum Theme {
19 Light,
20 Dark,
21}
22
23pub type RedrawHandler = Box<dyn FnOnce(winit::dpi::PhysicalSize<u32>, EguiCommand) + Send>;
25
26pub enum HandleRedraw {
28 Auto,
29 Handle(RedrawHandler),
30}
31
32pub trait App {
34 fn ui(&mut self, ctx: &egui::Context);
36
37 fn handle_event(&mut self, _event: event::Event) {}
39
40 fn request_redraw(&mut self, _viewport_id: egui::ViewportId) -> HandleRedraw {
49 HandleRedraw::Auto
50 }
51
52 #[cfg(feature = "persistence")]
54 fn auto_save_interval(&self) -> std::time::Duration {
55 std::time::Duration::from_secs(30)
56 }
57
58 #[cfg(feature = "persistence")]
60 fn save(&mut self, _storage: &mut storage::Storage) {}
61}
62
63pub struct CreationContext<'a> {
65 pub main_window: &'a winit::window::Window,
67
68 pub context: egui::Context,
70
71 pub required_instance_extensions: Vec<CString>,
73
74 pub required_device_extensions: Vec<CString>,
76
77 pub image_registry: ImageRegistry,
79
80 pub exit_signal: ExitSignal,
82}
83
84pub struct AshRenderState<A: Allocator + 'static> {
87 pub entry: Entry,
88 pub instance: Instance,
89 pub physical_device: vk::PhysicalDevice,
90 pub device: Device,
91 pub surface_loader: Surface,
92 pub swapchain_loader: Swapchain,
93 pub queue: vk::Queue,
94 pub queue_family_index: u32,
95 pub command_pool: vk::CommandPool,
96 pub allocator: A,
97}
98
99pub trait AppCreator<A: Allocator + 'static> {
101 type App: App;
102
103 fn create(&self, cc: CreationContext) -> (Self::App, AshRenderState<A>);
105}