Basic window creation

This commit is contained in:
Jarrod Doyle 2024-03-07 15:36:57 +00:00
parent 91e06c597e
commit d25d006cec
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
3 changed files with 2228 additions and 2 deletions

2179
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -6,3 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
anyhow = "1.0.80"
env_logger = "0.11.3"
log = "0.4.21"
wgpu = "0.19.3"
winit = "0.29.14"

View File

@ -1,3 +1,45 @@
fn main() { use anyhow::Result;
println!("Hello, world!"); use winit::{
dpi::LogicalSize,
event::*,
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
window::{Window, WindowBuilder},
};
pub fn main() -> Result<()> {
env_logger::init();
let (event_loop, window) = make_window()?;
run(event_loop, window)?;
Ok(())
}
pub fn run(event_loop: EventLoop<()>, window: Window) -> Result<()> {
event_loop.run(|event, elwt| match event {
Event::WindowEvent { window_id, event } if window_id == window.id() => {
handle_window_event(event, elwt);
}
_ => (),
})?;
Ok(())
}
fn make_window() -> Result<(EventLoop<()>, Window)> {
let event_loop = EventLoop::new()?;
event_loop.set_control_flow(ControlFlow::Wait);
let window = WindowBuilder::new()
.with_title("Sigil")
.with_inner_size(LogicalSize::new(1280.0, 720.0))
.build(&event_loop)?;
Ok((event_loop, window))
}
fn handle_window_event(event: WindowEvent, elwt: &EventLoopWindowTarget<()>) {
if let WindowEvent::CloseRequested = event {
elwt.exit();
}
} }