Skip to main content

WindowOptions

Struct WindowOptions 

Source
pub struct WindowOptions {
Show 13 fields pub title: String, pub size: Size, pub clear_color: Color, pub repaint: RepaintMode, pub show_damage: bool, pub renderer: RendererChoice, pub stats: Option<PresentStatsHandle>, pub on_frame: Option<FrameHook>, pub on_event: Option<EventHook>, pub frame_limit: Option<u64>, pub decorations: bool, pub min_size: Option<Size>, pub app_id: Option<String>,
}
Expand description

The settings a window opens with.

Fields§

§title: String

The text shown in the window’s title bar.

§size: Size

The size of the window’s content area in logical pixels.

§clear_color: Color

The color the renderer fills the surface with before it replays the display list.

Must be opaque, because presentation copies only the color channels of the surface into the window. A run with a color that is not opaque returns PlatformError::ClearColor before a window opens.

§repaint: RepaintMode

How much of the surface each frame repaints.

§show_damage: bool

Whether every present tints the pixels the frame repainted.

A debugging aid for damage regressions: while it is on, every present copies the whole pixmap and blends a translucent tint over the frame’s damage rectangles in the window buffer alone, so the window shows what each frame paid for. Damage presentation is off while the overlay is on, and neither the renderer’s pixmap nor a later frame keeps a tint.

The overlay exists on the CPU renderer only, so it makes RendererChoice::Auto pick the CPU renderer, and it cannot be combined with RendererChoice::Gpu.

§renderer: RendererChoice

Which renderer presents the frames.

RendererChoice::Auto uses the GPU renderer only when the window’s adapter is a real GPU, and falls back to the CPU renderer on a software rasterizer, without one, or on a window the GPU cannot present to. It is the default in builds with the gpu feature. RendererChoice::Gpu never falls back to the CPU renderer: it fails the run when the gpu feature is off or no backend, OpenGL included, has a usable adapter.

The crate::renderer::RENDERER_ENVIRONMENT variable, set to cpu, gpu or auto, overrides the value here when the window opens, so a machine can switch renderer without a rebuild.

§stats: Option<PresentStatsHandle>

Where the platform publishes presentation statistics, when given.

Pass a PresentStatsHandle and keep the original to read the PresentStats of the most recent present while the window runs. Without one the platform skips publishing.

§on_frame: Option<FrameHook>

Measurement hook: runs after every presented frame.

The hook receives the frame’s FrameStats and the present’s PresentStats, in that order. It runs on the main thread between frames and must not touch the window. A frame rendered while the surface has no pixel, for example while the window is minimized, is not presented, so it neither calls the hook nor counts toward the frame limit.

§on_event: Option<EventHook>

Measurement hook: injects input before every frame.

The hook receives the app and may hand it input events through App::handle_event, which is the path every real event takes, so the frame that follows shows the event and measures its latency. A run with this hook draws frames back to back like a run with a tick. Like a ticked frame, a frame whose input changed nothing presents nothing, so it neither calls WindowOptions::on_frame nor counts toward the frame limit. A hook that must reach its limit changes something in every frame.

§frame_limit: Option<u64>

Measurement hook: closes the window after this many presented frames.

A run that must last a fixed number of frames sets this instead of waiting for the user to close the window. Until the limit is reached, every presented frame asks for the next one, as if the app ran a tick, so a window whose app has nothing more to draw still closes: such a frame presents the last picture again, paced by the display. A frame that presents nothing, because the surface has no pixels to show, asks for none, so the run waits for the window to change instead of spinning.

§decorations: bool

Whether the window system draws its own decorations around the window.

An application that draws its own title bar turns this off and starts moves and resizes itself through the window commands.

§min_size: Option<Size>

The smallest size the user can resize the window to, in logical pixels.

None, the default, puts no limit on the resize.

§app_id: Option<String>

The name the window system reports for the application.

On Wayland this is the xdg_toplevel app id, and on X11 both parts of the WM_CLASS, so a desktop can match the window to a .desktop entry. On the other platforms the field has no effect.

Trait Implementations§

Source§

impl Clone for WindowOptions

Source§

fn clone(&self) -> Self

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 Debug for WindowOptions

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WindowOptions

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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> 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
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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

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

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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