diff --git a/Cargo.lock b/Cargo.lock index 0b5ee9e..9577500 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,6 +1242,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "pollster" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" + [[package]] name = "portable-atomic" version = "1.13.1" @@ -1668,6 +1674,15 @@ dependencies = [ "strict-num", ] +[[package]] +name = "tokio" +version = "1.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +dependencies = [ + "pin-project-lite", +] + [[package]] name = "toml_datetime" version = "1.1.1+spec-1.1.0" @@ -2401,6 +2416,9 @@ checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" name = "wsg-examples" version = "0.1.0" dependencies = [ + "pollster", + "tokio", + "winit", "wsg-lib", ] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 7c2978d..fb27ac2 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -6,3 +6,6 @@ edition = "2024" [dependencies] # On pointe vers le chemin relatif de la librairie wsg-lib = { path = "../lib" } +pollster = "0.4.0" +tokio = { version = "1", features = ["rt-multi-thread"] } +winit = "0.30" diff --git a/examples/src/main.rs b/examples/src/main.rs index 9cbc2e7..9d9651c 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -1,3 +1,47 @@ -fn main() { - todo!("later"); +use winit::{ + application::ApplicationHandler, + event::WindowEvent, + event_loop::{ActiveEventLoop, EventLoop}, + window::{WindowAttributes, WindowId}, +}; + +use std::sync::Arc; +use wsg_lib::context::Context; + +struct AppState { + context: Option, +} + +impl ApplicationHandler for AppState { + fn resumed(&mut self, event_loop: &ActiveEventLoop) { + let window_attributes = WindowAttributes::default() + .with_title("Test WSG"); + + let window = Arc::new( + event_loop + .create_window(window_attributes) + .unwrap(), + ); + + let rt = tokio::runtime::Runtime::new().unwrap(); + self.context = Some(rt.block_on(Context::new(window)).unwrap()); + } + + fn window_event( + &mut self, + _event_loop: &ActiveEventLoop, + _window_id: WindowId, + event: WindowEvent, + ) { + match event { + WindowEvent::CloseRequested => {}, // stop the app + _ => (), + } + } +} + +fn main() { + let mut app_state = AppState { context: None }; + let event_loop = EventLoop::new().unwrap(); + event_loop.run_app(&mut app_state).unwrap(); }