Skip to main content

WindowConfig

Struct WindowConfig 

Source
pub struct WindowConfig { /* private fields */ }
Expand description

Window configuration for run_windowed / run_app.

Deliberately renderer-agnostic: pixel dimensions, not grid/font/scale. Use fit to derive the pixel size from a presenter’s own cell geometry.

Implementations§

Source§

impl WindowConfig

Source

pub fn fit<P: Presenter>( presenter: &P, title: impl Into<String>, target_fps: Option<u32>, ) -> Self

Size the window to exactly fit presenter’s grid: cols x cell_w by rows x cell_h physical pixels.

This is why renderer crates don’t need their own windowing code: the grid/cell geometry already lives behind Output::size and Presenter::cell_size.

target_fps is an optional frame-rate cap: None runs uncapped on native (the event loop re-renders as fast as the backend allows) or at display refresh on wasm32 (always requestAnimationFrame-driven there regardless of this setting).

Source

pub fn title(&self) -> &str

The window title, as set by fit.

Source

pub const fn width(&self) -> u32

Initial inner width in physical pixels, as computed by fit.

Source

pub const fn height(&self) -> u32

Initial inner height in physical pixels, as computed by fit.

Source

pub const fn target_fps(&self) -> Option<u32>

The frame-rate cap passed to fit, if any.

Source

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

Sets whether to size (and keep resizing) the canvas to fill the browser viewport on wasm32, instead of the pixel size fit computed – a full-screen, mobile-web-app feel for games that want it. Has no effect on native, where the OS window is already sized by fit and the window manager owns further resizing either way.

Defaults to false: most demos/examples should render at their natural grid size (cols x cell_w by rows x cell_h) wherever they land on the page, not stretch to fill whatever viewport happens to be hosting them. Opt in explicitly for an app-like, full-screen game.

Source

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

Sets whether the window can be resized by the user/window manager after creation.

Defaults to true (winit’s own default). Set to false for fixed-size retro windows where the grid is meant to stay put – resizing a pseudo-graphic UI usually means picking a new grid size, not stretching cells, and most callers that care already size the window to their content via fit.

On wasm32, winit’s web backend ignores this (there is no OS-level resize grip on a canvas); it’s still applied for source-level parity with native, it just has no effect.

Source

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

Sets whether the window has OS chrome: title bar, borders, close/minimize/maximize buttons.

Defaults to true (winit’s own default). Set to false for a borderless window (custom-drawn title bars, retro full-bleed layouts).

On wasm32, winit’s web backend ignores this (a canvas has no OS chrome to begin with); it’s still applied for source-level parity with native, it just has no effect.

Source

pub const fn min_size(self, width: u32, height: u32) -> Self

Sets the minimum inner (content) size in physical pixels.

Defaults to no minimum.

Source

pub const fn max_size(self, width: u32, height: u32) -> Self

Sets the maximum inner (content) size in physical pixels.

Defaults to no maximum.

Source

pub const fn initial_position(self, x: i32, y: i32) -> Self

Sets the desired initial outer window position in physical pixels.

Defaults to letting the platform choose.

On wasm32, winit’s web backend maps this to the canvas’s position: absolute left/top, which only does anything if the page’s CSS has already opted the canvas into absolute/relative positioning; otherwise normal document flow overrides it.

Source

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

Sets whether to request borderless fullscreen (on the window’s current monitor) at creation.

Defaults to false. This only exposes borderless fullscreen, not winit’s exclusive-fullscreen video-mode API: retro/terminal-style apps render a fixed cell grid, not a resolution-dependent 3D scene, so there is no benefit to an exclusive video-mode switch, only extra platform-specific complexity (enumerating VideoModeHandles) for a mode real games would rarely want here.

On wasm32, winit’s web backend maps this to the browser’s Fullscreen API (Element.requestFullscreen), which most browsers refuse to grant without a user gesture; requesting it unconditionally at window-creation time (before any gesture) is liable to silently fail there. Still applied for source-level parity with native.

Source

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

Sets whether the window’s background supports transparency (alpha blending with whatever is behind it).

Defaults to false (winit’s own default).

On wasm32, winit’s web backend ignores this (a canvas is already alpha-blended with the page behind it via normal CSS compositing); it’s still applied for source-level parity with native, it just has no effect.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more