Basic window creation
This commit is contained in:
parent
91e06c597e
commit
d25d006cec
File diff suppressed because it is too large
Load Diff
|
@ -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"
|
||||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue