|
| 1 | +#![allow(clippy::single_match)] |
| 2 | + |
| 3 | +// Limit this example to only compatible platforms. |
| 4 | +#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform,))] |
| 5 | +fn main() -> std::process::ExitCode { |
| 6 | + use std::{process::ExitCode, thread::sleep, time::Duration}; |
| 7 | + |
| 8 | + use simple_logger::SimpleLogger; |
| 9 | + use winit::{ |
| 10 | + event::{Event, PumpStatus, WindowEvent}, |
| 11 | + event_loop::EventLoop, |
| 12 | + platform::pump_events::EventLoopExtPumpEvents, |
| 13 | + window::WindowBuilder, |
| 14 | + }; |
| 15 | + let mut event_loop = EventLoop::new(); |
| 16 | + |
| 17 | + SimpleLogger::new().init().unwrap(); |
| 18 | + let window = WindowBuilder::new() |
| 19 | + .with_title("A fantastic window!") |
| 20 | + .build(&event_loop) |
| 21 | + .unwrap(); |
| 22 | + |
| 23 | + 'main: loop { |
| 24 | + let status = event_loop.pump_events(|event, _, control_flow| { |
| 25 | + if let Event::WindowEvent { event, .. } = &event { |
| 26 | + // Print only Window events to reduce noise |
| 27 | + println!("{:?}", event); |
| 28 | + } |
| 29 | + |
| 30 | + match event { |
| 31 | + Event::WindowEvent { |
| 32 | + event: WindowEvent::CloseRequested, |
| 33 | + window_id, |
| 34 | + } if window_id == window.id() => control_flow.set_exit(), |
| 35 | + Event::MainEventsCleared => { |
| 36 | + window.request_redraw(); |
| 37 | + } |
| 38 | + _ => (), |
| 39 | + } |
| 40 | + }); |
| 41 | + if let PumpStatus::Exit(exit_code) = status { |
| 42 | + break 'main ExitCode::from(exit_code as u8); |
| 43 | + } |
| 44 | + |
| 45 | + // Sleep for 1/60 second to simulate rendering |
| 46 | + println!("rendering"); |
| 47 | + |
| 48 | + let _dialog = rfd::MessageDialog::new() |
| 49 | + .set_title("Msg!") |
| 50 | + .set_description("Description!") |
| 51 | + .set_buttons(rfd::MessageButtons::YesNo) |
| 52 | + .show(); |
| 53 | + |
| 54 | + sleep(Duration::from_millis(33)); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +#[cfg(any(target_os = "ios", target_arch = "wasm32"))] |
| 59 | +fn main() { |
| 60 | + println!("This platform doesn't support pump_events."); |
| 61 | +} |
0 commit comments