pub struct Window { /* private fields */ }
Expand description
A cross-platform window wrapper.
§Examples
use simple_window::{Window, WindowEvent, WindowInputEvent};
fn main() {
let mut is_running = true;
let mut window = Window::new("Example Window", 200, 200, 400, 600);
while is_running {
window.poll_messages(|event| {
match event {
WindowEvent::Close => is_running = false,
WindowEvent::Resize(width, height) => println!("Window resized: {}, {}", width, height),
WindowEvent::Input(event) => match event {
WindowInputEvent::MouseMove(x, y) => println!("Mouse moved!: {}, {}", x, y),
WindowInputEvent::KeyDown(key) => println!("Key pressed: {}", key.as_str()),
WindowInputEvent::KeyUp(key) => println!("Key released: {}", key.as_str()),
WindowInputEvent::MouseWheelMove(dz) => println!("Mouse wheel {}", if dz > 0 { "up" } else { "down" }),
WindowInputEvent::MouseDown(button) => println!("Mouse {} down.", button.as_str()),
WindowInputEvent::MouseUp(button) => println!("Mouse {} up.", button.as_str()),
},
}
});
}
}
Implementations§
Source§impl Window
impl Window
Sourcepub fn new(window_name: &str, x: i32, y: i32, width: i32, height: i32) -> Self
pub fn new(window_name: &str, x: i32, y: i32, width: i32, height: i32) -> Self
Creates a new window at position (x
, y
), and name window_name
.
Sourcepub fn poll_messages(&mut self, event_closure: impl FnMut(WindowEvent))
pub fn poll_messages(&mut self, event_closure: impl FnMut(WindowEvent))
Polls and parses system messages directed at the window and passes them on to the event_closure
closure.
pub fn raw_window_handle(&self) -> RawWindowHandle
pub fn raw_display_handle(&self) -> RawDisplayHandle
Auto Trait Implementations§
impl Freeze for Window
impl RefUnwindSafe for Window
impl Send for Window
impl Sync for Window
impl Unpin for Window
impl UnwindSafe for Window
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more