Struct minifb::Window [] [src]

pub struct Window(_);

Window is used to open up a window. It's possible to optionally display a 32-bit buffer when the widow is set as non-resizable.

Methods

impl Window
[src]

[src]

Opens up a new window

# Examples

Open up a window with default settings

Be careful when using this code, it's not being tested!
let mut window = match Window::new("Test", 640, 400, WindowOptions::default()) {
    Ok(win) => win,
    Err(err) => {
        println!("Unable to create window {}", err);
        return;
    }
};

Open up a window that is resizeable

Be careful when using this code, it's not being tested!
let mut window = match Window::new("Test", 640, 400,
                                     WindowOptions {
                                         resize: true,
                                         ..WindowOptions::default()
                                     }) {
    Ok(win) => win,
    Err(err) => {
        println!("Unable to create window {}", err);
        return;
    }
};

[src]

Allows you to set a new title of the window after creation

Examples

Be careful when using this code, it's not being tested!
let mut window = match Window::new("Test", 640, 400, WindowOptions::default()).unwrap();

window.set_title("My New Title!");

[src]

Returns the native handle for a window which is an opaque pointer/handle which dependens on the current operating system:

Be careful when using this code, it's not being tested!
Windows HWND
MacOS   NSWindow
X11     XWindow

[src]

Updates the window with a 32-bit pixel buffer. Notice that the buffer needs to be at least the size of the created window

Examples

Be careful when using this code, it's not being tested!
let mut buffer: Vec<u32> = vec![0; 640 * 400];

let mut window = match Window::new("Test", 640, 400, WindowOptions::default()).unwrap();

window.update_with_buffer(&buffer).unwrap();

[src]

Updates the window (this is required to call in order to get keyboard/mouse input, etc)

Examples

Be careful when using this code, it's not being tested!
let mut buffer: Vec<u32> = vec![0; 640 * 400];

let mut window = match Window::new("Test", 640, 400, WindowOptions::default()).unwrap();

window.update();

[src]

Checks if the window is still open. A window can be closed by the user (by for example pressing the close button on the window) It's up to the user to make sure that this is being checked and take action depending on the state.

Examples

Be careful when using this code, it's not being tested!
while window.is_open() {
    window.update(...)
}

[src]

Sets the position of the window. This is useful if you have more than one window and want to align them up on the screen

Examples

Be careful when using this code, it's not being tested!
// Moves the window to pixel position 20, 20 on the screen
window.set_position(20, 20);

[src]

Returns the current size of the window

Examples

Be careful when using this code, it's not being tested!
let size = window.get_size();
println!("width {} height {}", size.0, size.1);

[src]

Get the current position of the mouse relative to the current window The coordinate system is as 0, 0 as the upper left corner

Examples

Be careful when using this code, it's not being tested!
window.get_mouse_pos(MouseMode::Clamp).map(|mouse| {
    println!("x {} y {}", mouse.0, mouse.1);
});

[src]

Get the current position of the mouse relative to the current window The coordinate system is as 0, 0 as the upper left corner and ignores any scaling set to the window.

Examples

Be careful when using this code, it's not being tested!
window.get_unscaled_mouse_pos(MouseMode::Clamp).map(|mouse| {
    println!("x {} y {}", mouse.0, mouse.1);
});

[src]

Check if a mouse button is down or not

Examples

Be careful when using this code, it's not being tested!
let left_down = window.get_mouse_down(MouseButton::Left);
println!("is left down? {}", left_down)

[src]

Get the current movement of the scroll wheel. Scroll wheel can mean different thing depending on the device attach. For example on Mac with trackpad "scroll wheel" means two finger swiping up/down (y axis) and to the sides (x-axis) When using a mouse this assumes the scroll wheel which often is only y direction.

Examples

Be careful when using this code, it's not being tested!
window.get_scroll_wheel().map(|scroll| {
    println!("scrolling - x {} y {}", scroll.0, scroll.1);
});

[src]

Set a different cursor style. This can be used if you have resizing elements or something like that

Examples

Be careful when using this code, it's not being tested!
window.set_cursor_style(CursorStyle::ResizeLeftRight);

[src]

Get the current keys that are down.

Examples

Be careful when using this code, it's not being tested!
window.get_keys().map(|keys| {
    for t in keys {
        match t {
            Key::W => println!("holding w"),
            Key::T => println!("holding t"),
            _ => (),
        }
    }
});

[src]

Get the current pressed keys. Repeat can be used to control if keys should be repeated if down or not.

Examples

Be careful when using this code, it's not being tested!
window.get_keys_pressed(KeyRepeat::No).map(|keys| {
    for t in keys {
        match t {
            Key::W => println!("pressed w"),
            Key::T => println!("pressed t"),
            _ => (),
        }
    }
});

[src]

Check if a single key is down.

Examples

Be careful when using this code, it's not being tested!
if window.is_key_down(Key::A) {
    println!("Key A is down");
}

[src]

Check if a single key is pressed. KeyRepeat will control if the key should be repeated or not while being pressed.

Examples

Be careful when using this code, it's not being tested!
if window.is_key_pressed(KeyRepeat::No) {
    println!("Key A is down");
}

[src]

Sets the delay for when a key is being held before it starts being repeated the default value is 0.25 sec

Examples

Be careful when using this code, it's not being tested!
window.set_key_repeat_delay(0.5) // 0.5 sec before repeat starts

[src]

Sets the rate in between when the keys has passed the initial repeat_delay. The default value is 0.05 sec

Examples

Be careful when using this code, it's not being tested!
window.set_key_repeat_rate(0.01) // 0.01 sec between keys

[src]

Returns if this windows is the current active one

[src]

Set input callback to recive callback on char input

[src]

This allows adding menus to your windows. As menus behaves a bit diffrently depending on Operating system here is how it works.

Be careful when using this code, it's not being tested!
Windows:
  Each window has their own menu and shortcuts are active depending on active window.
Mac:
  As Mac uses one menu for the whole program the menu will change depending
  on which window you have active.
Linux/BSD/etc:
  Menus aren't supported as they depend on each WindowManager and is outside of the
  scope for this library to support. Use [get_unix_menus] to get a structure

[src]

Remove a menu that has been added with [#add_menu]

[src]

[src]

Check if a menu item has been pressed