winit_app/
lib.rs

1//!
2//! This library helps get started with the `winit` library , the rust windowing toolkit to get started.
3//!
4//! ## Usage
5//!
6//! Create a new winit application using this library to get started.
7//!  
8//! ```
9//! use winit::{event::WindowEvent, window::WindowAttributes};
10//! use winit_app::{AppWindowEvent, Application};
11//!
12//! fn launch_app() -> Result<(), Box<dyn std::error::Error>> {
13//!     let winit_app = Application::new();
14//!
15//!     winit_app.run(
16//!        WindowAttributes::default().with_title("Sample"),
17//!        |app_window_event| match app_window_event {
18//!            AppWindowEvent::NewWindow(_window) => {
19//!                // TODO: Do something with this window
20//!                
21//!            }
22//!            AppWindowEvent::OnWindowEvent(event, event_loop) => match event {
23//!                WindowEvent::CloseRequested => {
24//!                   // Just a default handler to exit the event_loop when window is being closed  
25//!                    event_loop.exit();
26//!                }
27//!                _ => {
28//!                    // Handle all other window events
29//!                }
30//!            },
31//!        },
32//!    )?;
33//!    Ok(())
34//! }
35//! ```
36//!
37//!
38mod app_listener;
39mod application;
40
41pub use app_listener::AppWindowEvent;
42pub use application::Application;
43
44use thiserror::Error;
45use winit::error::EventLoopError;
46
47/// WinitAppError indicates the possible errors from the winit framework
48#[derive(Error, Debug)]
49pub enum WinitAppError {
50    #[error(transparent)]
51    EventLoopError(#[from] EventLoopError),
52    #[error(transparent)]
53    WinitOSError(#[from] winit::error::OsError),
54    #[error(transparent)]
55    WinitRequestError(#[from] winit::error::RequestError),
56}
57
58pub type WinitAppResult<T> = Result<T, WinitAppError>;