I can't seem to figure out how to create a window. Help! #3923
-
Hello! I'm new to Rust and Here's the code I've come up with. use winit::{
application::ApplicationHandler,
error::EventLoopError,
event::WindowEvent,
event_loop::EventLoop,
window::Window
};
#[derive(Default)]
struct App {
window: Option<Window>,
}
impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
self.window = Some(
event_loop
.create_window(Window::default_attributes())
.expect("Couldn't create window"),
);
}
fn window_event(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
_window_id: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
match event {
WindowEvent::CloseRequested => {
println!("Close button pressed. Exiting...");
event_loop.exit();
},
WindowEvent::RedrawRequested => {
self.window.as_ref().unwrap().request_redraw();
},
_ => (),
}
}
}
fn main() -> Result<(), EventLoopError> {
let event_loop = EventLoop::new()?;
let mut app = App::default();
event_loop.run_app(&mut app)
} I have created this by looking at both the System info
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
winit = "0.30.5" Any pointers would be greatly appreciated! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to draw into window on Wayland for it to show up (the same will apply for XWayland, you'd still need to draw). Only on plain X11 it'll show up something without drawing anything at all. |
Beta Was this translation helpful? Give feedback.
You need to draw into window on Wayland for it to show up (the same will apply for XWayland, you'd still need to draw). Only on plain X11 it'll show up something without drawing anything at all.