Skip to main content

myth_app/
window.rs

1//! Platform-independent window abstraction.
2//!
3//! Defines a [`Window`] trait that decouples application logic from
4//! specific windowing backends (e.g., winit). User code interacts with
5//! this trait instead of concrete window types.
6//!
7//! When using the `winit` backend, the concrete implementation is
8//! `winit::window::Window`. Advanced users can downcast via [`Window::as_any`]
9//! to access platform-specific functionality.
10
11use glam::Vec2;
12
13/// Platform-independent window interface.
14///
15/// Provides core window operations that application code typically needs:
16/// setting the title, querying dimensions, requesting redraws, etc.
17///
18/// # Backend Access
19///
20/// For advanced use cases (e.g., UI framework integration), the underlying
21/// platform window can be accessed via [`as_any`](Self::as_any) and downcasting:
22///
23/// ```rust,ignore
24/// // When using the winit backend:
25/// if let Some(winit_window) = window.as_any().downcast_ref::<winit::window::Window>() {
26///     // Access winit-specific APIs
27/// }
28/// ```
29pub trait Window: Send + Sync {
30    /// Sets the window title.
31    fn set_title(&self, title: &str);
32
33    /// Returns the window's inner (client area) size in physical pixels.
34    fn inner_size(&self) -> Vec2;
35
36    /// Returns the display scale factor (DPI scaling).
37    fn scale_factor(&self) -> f32;
38
39    /// Requests the window to redraw.
40    fn request_redraw(&self);
41
42    /// Shows or hides the mouse cursor.
43    fn set_cursor_visible(&self, visible: bool);
44
45    /// Returns the underlying platform window as `Any` for downcasting.
46    ///
47    /// This enables advanced users to access platform-specific APIs
48    /// without coupling the core engine to any particular windowing backend.
49    fn as_any(&self) -> &dyn std::any::Any;
50}