// Copyright 2023 The ChromiumOS Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. cfg_if::cfg_if! { if #[cfg(unix)] { pub mod unix; pub use unix as platform; pub(crate) use self::unix::StubWindowEventLoop as PlatformWindowEventLoop; } else if #[cfg(windows)] { pub mod windows; pub use windows as platform; pub(crate) use self::windows::WindowsWindowEventLoop as PlatformWindowEventLoop; } } use std::any::Any; use std::sync::Arc; use anyhow::Result; use euclid::Box2D; use euclid::Size2D; use euclid::UnknownUnit; use vulkano::instance::Instance; use vulkano::swapchain; type Surface = swapchain::Surface>; pub trait Window: Any + Send + Sync { fn get_inner_size(&self) -> Result>; fn create_vulkan_surface(self: Arc, instance: Arc) -> Result>; } pub trait ApplicationState { type UserEvent: Send + 'static; fn process_event(&self, event: WindowEvent); } pub trait ApplicationStateBuilder: Send + 'static { type Target: ApplicationState; fn build(self, window: Arc) -> Result; } // Some platform may not support all the events. #[allow(dead_code)] pub enum WindowEvent { Resized, User(T), } pub trait WindowEventLoop: Sized + Send { type WindowType: Window; /// # Safety /// The parent window must outlive the lifetime of this object. unsafe fn create( parent: platform::NativeWindowType, initial_window_size: &Size2D, application_state_builder: Builder, ) -> Result where Builder: ApplicationStateBuilder; fn send_event(&self, event: State::UserEvent) -> Result<()>; fn move_window(&self, pos: &Box2D) -> Result<()>; }