anvilkit_render/window/mod.rs
1//! # 窗口管理模块
2//!
3//! 提供基于 winit 的跨平台窗口管理功能,包括窗口创建、事件处理和应用生命周期管理。
4//!
5//! ## 核心组件
6//!
7//! - **RenderApp**: 实现 ApplicationHandler 的主应用结构
8//! - **WindowConfig**: 窗口配置参数
9//! - **WindowState**: 窗口状态管理
10//!
11//! ## 设计理念
12//!
13//! 本模块采用最新的 winit 0.29 API 设计,使用 ApplicationHandler trait
14//! 替代旧的事件循环模式,提供更好的跨平台兼容性和性能。
15//!
16//! ## 使用示例
17//!
18//! ```rust,no_run
19//! use anvilkit_render::window::*;
20//! use winit::event_loop::EventLoop;
21//!
22//! // 创建事件循环和应用
23//! let event_loop = EventLoop::new().unwrap();
24//! let mut app = RenderApp::new(WindowConfig::default());
25//!
26//! // 运行应用
27//! event_loop.run_app(&mut app).unwrap();
28//! ```
29
30pub mod window;
31pub mod events;
32
33// 重新导出主要类型
34pub use window::{WindowConfig, WindowState};
35pub use events::{RenderApp, pack_lights, compute_light_space_matrix};
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn test_window_config_default() {
43 let config = WindowConfig::default();
44 assert_eq!(config.title, "AnvilKit Application");
45 assert_eq!(config.width, 1280);
46 assert_eq!(config.height, 720);
47 assert!(!config.fullscreen);
48 assert!(config.resizable);
49 assert!(config.visible);
50 }
51
52 #[test]
53 fn test_window_config_builder() {
54 let config = WindowConfig::new()
55 .with_title("Test Window")
56 .with_size(800, 600)
57 .with_fullscreen(true);
58
59 assert_eq!(config.title, "Test Window");
60 assert_eq!(config.width, 800);
61 assert_eq!(config.height, 600);
62 assert!(config.fullscreen);
63 }
64}