Skip to main content

WindowConfig

Struct WindowConfig 

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

Window configuration for run_windowed / run_app.

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

Several builder methods below (resizable, decorations, transparency, fullscreen) target an OS-level window control that a wasm32 canvas doesn’t have; on that target winit’s web backend either ignores the value outright or can’t reliably apply it (see each method for which, and why). The value is still applied for source-level parity with native either way, so the same call chain compiles and runs on both targets, it just may not visibly do anything in the browser.

Implementations§

Source§

impl WindowConfig

Source

pub fn fit<P: Presenter>( presenter: &P, title: impl Into<String>, target_fps: Option<u32>, event_driven: bool, ) -> 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 and event_driven are independent controls, on native and wasm32 alike:

  • target_fps is the frame-rate cap applied whenever a frame is actually rendered: None is uncapped (render as fast as the loop reaches a redraw), Some(fps) paces redraws to no more than fps per second.
  • event_driven picks between the two redraw-triggering modes:
    • true is redraw-on-demand: a frame is rendered only after something happened (an input or window event, an injected Event::Custom, window creation), and the loop sleeps otherwise. Right for event-driven retro/terminal UIs, which are idle most of the time; wrong for anything that animates from Frame::delta, which will render one frame and then sit still until the next stray event.
    • false is continuous: a frame is rendered every tick whether or not anything happened, which is what a retroglyph_ui::Tween/ FrameClock-driven app needs.

The two combine independently: (Some(fps), false) is the common capped-animation shape (see Self::animated for a shorthand), (None, true) is the common idle-UI shape, and (None, false) (render every tick, uncapped) is the one combination that was previously inexpressible, useful for e.g. measuring a render loop’s raw throughput.

On wasm32 the browser owns frame pacing: winit’s web backend delivers each requested redraw on the next requestAnimationFrame, so an uncapped or event_driven: false loop still runs at the display refresh rate and target_fps’s specific number is advisory (there is no way to render faster than requestAnimationFrame, and rendering slower would mean discarding frames the browser already scheduled). Only the event_driven choice carries across unaffected.

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 fn animated<P: Presenter>( presenter: &P, title: impl Into<String>, fps: u32, ) -> Self

Shorthand for fit with continuous, non-event-driven, fps-capped redraws: the shape most animated apps want. Equivalent to Self::fit(presenter, title, Some(fps), false).

Source

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

The frame-rate cap passed to fit; see its doc comment for what None vs. Some(fps) means and how it combines with event_driven.

Source

pub const fn event_driven(&self) -> bool

The redraw-triggering mode passed to fit; see its doc comment for what true vs. false means and how it combines with target_fps.

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.

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.

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.

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.

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
§

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

§

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

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

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

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

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

§

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

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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

§

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

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,