Feat: add hidden mode and new documentation

This commit is contained in:
2026-02-26 12:31:56 +01:00
parent e1cf57918e
commit 70032acc75
95 changed files with 1055 additions and 286 deletions

View File

@@ -1,3 +1,5 @@
//! Platform-independent window API and handler trait.
use std::marker::PhantomData;
use raw_window_handle::{
@@ -15,6 +17,7 @@ use crate::win as platform;
#[cfg(target_os = "linux")]
use crate::x11 as platform;
/// Opaque handle to an open window, used to close it or check liveness.
pub struct WindowHandle {
window_handle: platform::WindowHandle,
// so that WindowHandle is !Send on all platforms
@@ -44,11 +47,13 @@ unsafe impl HasRawWindowHandle for WindowHandle {
}
}
/// Trait implemented by the application to receive window events and frame callbacks.
pub trait WindowHandler {
fn on_frame(&mut self, window: &mut Window);
fn on_event(&mut self, window: &mut Window, event: Event) -> EventStatus;
}
/// A window that can be drawn to and receive events.
pub struct Window<'a> {
window: platform::Window<'a>,
@@ -67,6 +72,7 @@ impl<'a> Window<'a> {
Window { window, phantom: PhantomData }
}
/// Open a window as a child of the given parent.
pub fn open_parented<P, H, B>(parent: &P, options: WindowOpenOptions, build: B) -> WindowHandle
where
P: HasRawWindowHandle,
@@ -78,6 +84,7 @@ impl<'a> Window<'a> {
WindowHandle::new(window_handle)
}
/// Open a standalone window and block until it is closed.
pub fn open_blocking<H, B>(options: WindowOpenOptions, build: B)
where
H: WindowHandler + 'static,
@@ -103,14 +110,17 @@ impl<'a> Window<'a> {
self.window.resize(size);
}
/// Set the mouse cursor icon.
pub fn set_mouse_cursor(&mut self, cursor: MouseCursor) {
self.window.set_mouse_cursor(cursor);
}
/// Whether this window currently has keyboard focus.
pub fn has_focus(&mut self) -> bool {
self.window.has_focus()
}
/// Request keyboard focus for this window.
pub fn focus(&mut self) {
self.window.focus()
}