kozan_platform/host.rs
1//! Platform host — abstract interface from view threads to the main thread.
2//!
3//! Like Chrome's `WidgetHost` / `FrameWidgetHost` Mojo interfaces.
4//! The view thread communicates back to the main thread through this trait,
5//! never through windowing-backend types (winit, SDL2, etc.).
6//!
7//! The windowing backend (e.g., `kozan-winit`) provides the concrete
8//! implementation.
9
10use crate::id::WindowId;
11use crate::request::WindowConfig;
12
13/// The interface from a view thread back to the main thread.
14///
15/// Implemented by the windowing backend (e.g., `kozan-winit`).
16/// The view thread holds an `Arc<dyn PlatformHost>` and calls methods
17/// without knowing anything about the underlying windowing system.
18///
19/// All methods are non-blocking — they send messages to the main thread.
20/// If the main thread has exited, calls are silently dropped.
21pub trait PlatformHost: Send + Sync {
22 /// Request a redraw for this window.
23 fn request_redraw(&self, window_id: WindowId);
24
25 /// Set the window title.
26 fn set_title(&self, window_id: WindowId, title: &str);
27
28 /// Close the window.
29 fn close_window(&self, window_id: WindowId);
30
31 /// Resize the window.
32 fn resize_window(&self, window_id: WindowId, width: u32, height: u32);
33
34 /// Request a new window to be created.
35 fn create_window(&self, config: WindowConfig);
36}