Struct Window

Source
pub struct Window {
    pub handle: PWindow,
    pub events: GlfwReceiver<(f64, WindowEvent)>,
    /* private fields */
}
Expand description

It’s just a simple GLFW window holder with custom basic input system.

§Example

use tinystorm::window::{WindowBuilder};

let mut window = WindowBuilder::default()
    .with_size(800, 600)
    .with_title("My Window")
    .with_vsync(false)
    .with_max_fps(144 * 5)
    .with_msaa(4)
    .build();

while window.is_running() {
    window.poll_events();
    // Render your scene here
    window.swap_buffers();
}

Fields§

§handle: PWindow

GLFW window handle you can use for more precise control of your application.

§events: GlfwReceiver<(f64, WindowEvent)>

Current frame events you can use like a custom event handler. Updated only after Self::poll_events is called.

Implementations§

Source§

impl Window

Source

pub fn is_running(&self) -> bool

Is window still running. Primarily used in the main game loop.

§Example
while window.is_running() { ... }
Source

pub fn poll_events(&mut self)

Handles events in current frame. Please call it at the frame start to avoid input lag.

§Example
while window.is_running() {
    window.poll_events();
    ...
}
Source

pub fn swap_buffers(&mut self)

Swaps front framebuffer with back that scene was rendered on. Please call it at the frame end to avoid input lag.

§Example
while window.is_running() {
    ...
    window.swap_buffers();
}
Source

pub fn set_x(&mut self, value: i32)

Sets window X position in pixels from top-left corner

Source

pub fn set_y(&mut self, value: i32)

Sets window Y position in pixels from top-left corner

Source

pub fn set_position(&mut self, x: i32, y: i32)

Sets window position in pixels from top-left corner

Source

pub fn set_width(&mut self, value: i32)

Sets window width in pixels

Source

pub fn set_height(&mut self, value: i32)

Sets window height in pixels

Source

pub fn set_size(&mut self, width: i32, height: i32)

Sets window size in pixels

Source

pub fn set_title(&mut self, value: String)

Sets window title to a new one.

Source

pub fn get_title(&self) -> &str

Gets current window title.

Source

pub fn grab_mouse(&mut self)

Hides mouse and keeps it at the window center. Used primarily for first-person games where you don’t want to see the cursor.

Source

pub fn release_mouse(&mut self)

Shows mouse back and releases it from the window center. Used primarily for first-person games. For example, when you want to show a menu and release the mouse back.

Source

pub fn toggle_mouse(&mut self)

Changes mouse state to grabbed/released. If mouse is grabbed - it would be released, else - it would be grabbed.

Source

pub fn is_key_pressed(&self, key: Key) -> bool

Checks if specific key is pressed.

§Example
use tinystorm::{window::WindowBuilder, glfw::Key};
 
let mut window = WindowBuilder::default().build();
while window.is_running() {
    window.poll_events();
 
    // If key is pressed it would print "Key A is pressed!",
    // and it would print that each frame until key is released.
    if window.is_key_pressed(Key::A) {
        println!("Key A is pressed!");
    }
 
    window.swap_buffers();
}
Source

pub fn is_key_just_pressed(&self, key: Key) -> bool

Checks if specific key is just pressed.

§Example
use tinystorm::{window::WindowBuilder, glfw::Key};
 
let mut window = WindowBuilder::default().build();
while window.is_running() {
    window.poll_events();
 
    // If key was just pressed at this frame it would print "Key B is just pressed!",
    // but on next frame it wouldn't trigger.
    // 
    // Used primarily when you want to check if key is just clicked,
    // but not pressed for a certain time.
    if window.is_key_just_pressed(Key::B) {
        println!("Key B is just pressed!");
    }
 
    window.swap_buffers();
}
Source

pub fn is_mouse_button_pressed(&self, button: MouseButton) -> bool

Checks if specific mouse button is pressed.

§Example
use tinystorm::{window::WindowBuilder, glfw::MouseButton};
 
let mut window = WindowBuilder::default().build();
while window.is_running() {
    window.poll_events();
 
    // If mouse button is pressed it would print "Left mouse button is pressed!",
    // and it would print that each frame until mouse button is released.
    if window.is_mouse_button_pressed(MouseButton::Left) {
        println!("Left mouse button is pressed!");
    }
 
    window.swap_buffers();
}
Source

pub fn is_mouse_button_just_pressed(&self, button: MouseButton) -> bool

Checks if specific mouse button is just pressed.

§Example
use tinystorm::{window::WindowBuilder, glfw::MouseButton};
 
let mut window = WindowBuilder::default().build();
while window.is_running() {
    window.poll_events();
 
    // If mouse button was just pressed at this frame it would print "Middle mouse button is just pressed!",
    // but on next frame it wouldn't trigger.
    // 
    // Used primarily when you want to check if mouse button is just clicked,
    // but not pressed for a certain time.
    if window.is_mouse_button_just_pressed(MouseButton::Middle) {
        println!("Middle mouse button is just pressed!");
    }
 
    window.swap_buffers();
}
Source

pub fn get_mouse_x(&self) -> f32

Gets mouse cursor X position in pixels from top-left corner relative to window.

Source

pub fn get_mouse_y(&self) -> f32

Gets mouse cursor Y position in pixels from top-left corner relative to window.

Source

pub fn get_mouse_dx(&self) -> f32

Gets mouse cursor delta X position in pixels from top-left corner. It represents a horizontal mouse cursor movement in current frame.

Source

pub fn get_mouse_dy(&self) -> f32

Gets mouse cursor delta Y position in pixels from top-left corner. It represents a vertical mouse cursor movement in current frame.

Source

pub fn get_x(&self) -> i32

Gets window X position in pixels from top-left corner.

Source

pub fn get_y(&self) -> i32

Gets window Y position in pixels from top-left corner.

Source

pub fn get_width(&self) -> u32

Gets window width in pixels.

Source

pub fn get_height(&self) -> u32

Gets window height in pixels.

Source

pub fn get_aspect(&self) -> f32

Gets window aspect ratio. Formula: window.get_width() as f32 / window.get_height() as f32

Source

pub fn get_delta_raw(&self) -> Duration

Gets delta time between last and current frames as Duration so you can get it in any format you want. It’s used primarily for physics calculation, player movement or animations that are time-related.

Source

pub fn get_delta(&self) -> f32

Gets delta time between last and current frames in seconds. It’s used primarily for physics calculation, player movement or animations that are time-related.

Source

pub fn is_mouse_grabbed(&self) -> bool

Returns if mouse is grabbed (it means it’s hidden and moved to window center, primarily used for first-person games) or released.

Source

pub fn close(&mut self)

Turn off the window prematurely. (It would just make Window::is_running() false)

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.