use ash::{
extensions::khr::{Surface, Swapchain},
vk, Device, Entry, Instance,
};
use egui_winit::winit;
use std::{ffi::CString, sync::Arc};
#[cfg(feature = "persistence")]
use crate::storage;
use crate::{
event,
renderer::{EguiCommand, ImageRegistry},
Allocator,
};
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Theme {
Light,
Dark,
}
pub type RedrawHandler = Box<dyn FnOnce(winit::dpi::PhysicalSize<u32>, EguiCommand) + Send>;
pub enum HandleRedraw {
Auto,
Handle(RedrawHandler),
}
pub trait App {
fn ui(&mut self, ctx: &egui::Context);
fn handle_event(&mut self, _event: event::Event) {}
fn request_redraw(&mut self, _viewport_id: egui::ViewportId) -> HandleRedraw {
HandleRedraw::Auto
}
#[cfg(feature = "persistence")]
fn auto_save_interval(&self) -> std::time::Duration {
std::time::Duration::from_secs(30)
}
#[cfg(feature = "persistence")]
fn save(&mut self, _storage: &mut storage::Storage) {}
}
pub struct CreationContext<'a> {
pub main_window: &'a winit::window::Window,
pub context: egui::Context,
pub required_instance_extensions: Vec<CString>,
pub required_device_extensions: Vec<CString>,
pub image_registry: ImageRegistry,
}
pub struct AshRenderState<A: Allocator + 'static> {
pub entry: Arc<Entry>,
pub instance: Arc<Instance>,
pub physical_device: vk::PhysicalDevice,
pub device: Arc<Device>,
pub surface_loader: Arc<Surface>,
pub swapchain_loader: Arc<Swapchain>,
pub queue: vk::Queue,
pub queue_family_index: u32,
pub command_pool: vk::CommandPool,
pub allocator: A,
}
pub trait AppCreator<A: Allocator + 'static> {
type App: App;
fn create(&self, cc: CreationContext) -> (Self::App, AshRenderState<A>);
}