Struct Window

Source
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

Source

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.

Source

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.

Source

pub fn raw_window_handle(&self) -> RawWindowHandle

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.