Skip to main content

Window

Struct Window 

Source
#[non_exhaustive]
pub struct Window { pub title: &'static str, pub width: i32, pub height: i32, pub icon: Option<Icon>, pub vsync: bool, }
Expand description

The window a game opens. Build it with Window::new: a struct literal doesn’t compile outside this crate, so a new field never breaks a game (ADR-0039).

ⓘ
let window = shuyi_app::Window {
    title: "A game",
    width: 640,
    height: 480,
    icon: None,
    vsync: true,
};

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§title: &'static str

The title bar’s text.

§width: i32

The window’s size at start, in pixels (the window is resizable).

§height: i32

See width.

§icon: Option<Icon>

The window’s icon, if the game has one.

§vsync: bool

Whether the window asks the display’s driver for vsync: on by default (Window::new), so frames don’t tear. The driver may ignore it, and it is read only when the window opens, so it is the developer’s choice, not the player’s.

The frame cap (shuyi_ui::frame_cap, 60 frames a second unless the game or the player says) limits the rate either way, and never waits on top of vsync: on a 60 Hz display with vsync on, a cap of 60 leaves vsync to it. On a VRR display (G-Sync, FreeSync, adaptive sync) with vsync on, a cap a few frames under the display’s refresh (141 on a 144 Hz display) keeps it in its variable range, and the display follows the frames. A tick stage steps 60 times a second, so above 60 each step shows for whole frames: evenly at 120 and 240, but 2 and 3 frames in turn at 144 and 165; a cap that is a multiple of 60 avoids it.

Implementations§

Source§

impl Window

Source

pub const fn new(title: &'static str, width: i32, height: i32) -> Self

A window titled title, width × height pixels at start, with no icon (with_icon gives one) and vsync on (with_vsync turns it off).

Source

pub const fn with_icon(self, icon: Option<Icon>) -> Self

The window with icon (None for none): usable in a const item.

Source

pub const fn with_vsync(self, vsync: bool) -> Self

The window asking for vsync or not (vsync): usable in a const item.

Trait Implementations§

Source§

impl Clone for Window

Source§

fn clone(&self) -> Window

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Window

Source§

impl Debug for Window

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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.