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
impl WindowConfig
Sourcepub fn fit<P: Presenter>(
presenter: &P,
title: impl Into<String>,
target_fps: Option<u32>,
event_driven: bool,
) -> Self
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_fpsis the frame-rate cap applied whenever a frame is actually rendered:Noneis uncapped (render as fast as the loop reaches a redraw),Some(fps)paces redraws to no more thanfpsper second.event_drivenpicks between the two redraw-triggering modes:trueis redraw-on-demand: a frame is rendered only after something happened (an input or window event, an injectedEvent::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 fromFrame::delta, which will render one frame and then sit still until the next stray event.falseis continuous: a frame is rendered every tick whether or not anything happened, which is what aretroglyph_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.
Sourcepub fn animated<P: Presenter>(
presenter: &P,
title: impl Into<String>,
fps: u32,
) -> Self
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).
Sourcepub const fn target_fps(&self) -> Option<u32>
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.
Sourcepub const fn event_driven(&self) -> bool
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.
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.
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.
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.
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.
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.