Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created February 29, 2024 11:23
Show Gist options
  • Save thewh1teagle/a3806329ccfedab9c23616e029541e32 to your computer and use it in GitHub Desktop.
Save thewh1teagle/a3806329ccfedab9c23616e029541e32 to your computer and use it in GitHub Desktop.
use std::collections::HashMap;
use tao::{
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::{Window, WindowBuilder},
};
fn main() {
env_logger::init();
let event_loop = EventLoop::new();
let mut windows = HashMap::new();
for _ in 0..3 {
let window = WindowBuilder::new().with_focused(false).build(&event_loop).unwrap();
windows.insert(window.id(), window);
}
event_loop.run(move |event, event_loop, control_flow| {
*control_flow = ControlFlow::Wait;
if let Event::WindowEvent {
event, window_id, ..
} = event
{
match event {
WindowEvent::CloseRequested => {
println!("Window {:?} has received the signal to close", window_id);
// This drops the window, causing it to close.
windows.remove(&window_id);
if windows.is_empty() {
*control_flow = ControlFlow::Exit;
}
}
WindowEvent::KeyboardInput {
event: KeyEvent {
state: ElementState::Pressed,
..
},
..
} => {
let window = Window::new(event_loop).unwrap();
windows.insert(window.id(), window);
}
_ => (),
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment