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
impl WindowConfig
Sourcepub fn fit<P: Presenter>(
presenter: &P,
title: impl Into<String>,
target_fps: Option<u32>,
) -> Self
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).
Sourcepub const fn target_fps(&self) -> Option<u32>
pub const fn target_fps(&self) -> Option<u32>
The frame-rate cap passed to fit, if any.
Sourcepub const fn fill_viewport(self, fill_viewport: bool) -> Self
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.
Sourcepub const fn resizable(self, resizable: bool) -> Self
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.
Sourcepub const fn decorations(self, decorations: bool) -> Self
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.
Sourcepub const fn min_size(self, width: u32, height: u32) -> Self
pub const fn min_size(self, width: u32, height: u32) -> Self
Sets the minimum inner (content) size in physical pixels.
Defaults to no minimum.
Sourcepub const fn max_size(self, width: u32, height: u32) -> Self
pub const fn max_size(self, width: u32, height: u32) -> Self
Sets the maximum inner (content) size in physical pixels.
Defaults to no maximum.
Sourcepub const fn initial_position(self, x: i32, y: i32) -> Self
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.
Sourcepub const fn fullscreen(self, fullscreen: bool) -> Self
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.
Sourcepub const fn transparency(self, transparency: bool) -> Self
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§
impl Freeze for WindowConfig
impl RefUnwindSafe for WindowConfig
impl Send for WindowConfig
impl Sync for WindowConfig
impl Unpin for WindowConfig
impl UnsafeUnpin for WindowConfig
impl UnwindSafe for WindowConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.