Struct WindowResolution

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

Controls the size of a Window

§Physical, logical and requested sizes

There are three sizes associated with a window:

  • the physical size, which represents the actual height and width in physical pixels the window occupies on the monitor,
  • the logical size, which represents the size that should be used to scale elements inside the window, measured in logical pixels,
  • the requested size, measured in logical pixels, which is the value submitted to the API when creating the window, or requesting that it be resized.

§Scale factor

The reason logical size and physical size are separated and can be different is to account for the cases where:

  • several monitors have different pixel densities,
  • the user has set up a pixel density preference in its operating system,
  • the Bevy App has specified a specific scale factor between both.

The factor between physical size and logical size can be retrieved with WindowResolution::scale_factor.

For the first two cases, a scale factor is set automatically by the operating system through the window backend. You can get it with WindowResolution::base_scale_factor.

For the third case, you can override this automatic scale factor with WindowResolution::set_scale_factor_override.

§Requested and obtained sizes

The logical size should be equal to the requested size after creating/resizing, when possible. The reason the requested size and logical size might be different is because the corresponding physical size might exceed limits (either the size limits of the monitor, or limits defined in WindowResizeConstraints).

Note: The requested size is not kept in memory, for example requesting a size too big for the screen, making the logical size different from the requested size, and then setting a scale factor that makes the previous requested size within the limits of the screen will not get back that previous requested size.

Implementations§

Source§

impl WindowResolution

Source

pub fn new(physical_width: f32, physical_height: f32) -> WindowResolution

Creates a new WindowResolution.

Examples found in repository?
examples/window/scale_factor_override.rs (line 13)
9fn main() {
10    App::new()
11        .add_plugins(DefaultPlugins.set(WindowPlugin {
12            primary_window: Some(Window {
13                resolution: WindowResolution::new(500., 300.).with_scale_factor_override(1.0),
14                ..default()
15            }),
16            ..default()
17        }))
18        .add_systems(Startup, setup)
19        .add_systems(
20            Update,
21            (display_override, toggle_override, change_scale_factor),
22        )
23        .run();
24}
More examples
Hide additional examples
tests/window/resizing.rs (line 25)
20fn main() {
21    App::new()
22        .add_plugins(
23            DefaultPlugins.set(WindowPlugin {
24                primary_window: Some(Window {
25                    resolution: WindowResolution::new(MAX_WIDTH as f32, MAX_HEIGHT as f32)
26                        .with_scale_factor_override(1.0),
27                    title: "Resizing".into(),
28                    ..default()
29                }),
30                ..default()
31            }),
32        )
33        .insert_resource(Dimensions {
34            width: MAX_WIDTH,
35            height: MAX_HEIGHT,
36        })
37        .insert_resource(ContractingY)
38        .add_systems(Startup, (setup_3d, setup_2d))
39        .add_systems(Update, (change_window_size, sync_dimensions))
40        .run();
41}
examples/stress_tests/text_pipeline.rs (line 20)
14fn main() {
15    App::new()
16        .add_plugins((
17            DefaultPlugins.set(WindowPlugin {
18                primary_window: Some(Window {
19                    present_mode: PresentMode::AutoNoVsync,
20                    resolution: WindowResolution::new(1920.0, 1080.0)
21                        .with_scale_factor_override(1.0),
22                    ..default()
23                }),
24                ..default()
25            }),
26            FrameTimeDiagnosticsPlugin::default(),
27            LogDiagnosticsPlugin::default(),
28        ))
29        .insert_resource(WinitSettings {
30            focused_mode: UpdateMode::Continuous,
31            unfocused_mode: UpdateMode::Continuous,
32        })
33        .add_systems(Startup, spawn)
34        .add_systems(Update, update_text_bounds)
35        .run();
36}
examples/stress_tests/many_lights.rs (line 23)
18fn main() {
19    App::new()
20        .add_plugins((
21            DefaultPlugins.set(WindowPlugin {
22                primary_window: Some(Window {
23                    resolution: WindowResolution::new(1920.0, 1080.0)
24                        .with_scale_factor_override(1.0),
25                    title: "many_lights".into(),
26                    present_mode: PresentMode::AutoNoVsync,
27                    ..default()
28                }),
29                ..default()
30            }),
31            FrameTimeDiagnosticsPlugin::default(),
32            LogDiagnosticsPlugin::default(),
33            LogVisibleLights,
34        ))
35        .insert_resource(WinitSettings {
36            focused_mode: UpdateMode::Continuous,
37            unfocused_mode: UpdateMode::Continuous,
38        })
39        .add_systems(Startup, setup)
40        .add_systems(Update, (move_camera, print_light_count))
41        .run();
42}
examples/stress_tests/many_text2d.rs (line 78)
63fn main() {
64    // `from_env` panics on the web
65    #[cfg(not(target_arch = "wasm32"))]
66    let args: Args = argh::from_env();
67    #[cfg(target_arch = "wasm32")]
68    let args = Args::from_args(&[], &[]).unwrap();
69
70    let mut app = App::new();
71
72    app.add_plugins((
73        FrameTimeDiagnosticsPlugin::default(),
74        LogDiagnosticsPlugin::default(),
75        DefaultPlugins.set(WindowPlugin {
76            primary_window: Some(Window {
77                present_mode: PresentMode::AutoNoVsync,
78                resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0),
79                ..default()
80            }),
81            ..default()
82        }),
83    ))
84    .init_resource::<FontHandle>()
85    .add_systems(Startup, setup)
86    .add_systems(Update, (move_camera, print_counts));
87
88    if args.recompute {
89        app.add_systems(Update, recompute);
90    }
91
92    app.insert_resource(args).run();
93}
examples/stress_tests/many_materials.rs (line 29)
18fn main() {
19    // `from_env` panics on the web
20    #[cfg(not(target_arch = "wasm32"))]
21    let args: Args = argh::from_env();
22    #[cfg(target_arch = "wasm32")]
23    let args = Args::from_args(&[], &[]).unwrap();
24
25    App::new()
26        .add_plugins((
27            DefaultPlugins.set(WindowPlugin {
28                primary_window: Some(Window {
29                    resolution: WindowResolution::new(1920.0, 1080.0)
30                        .with_scale_factor_override(1.0),
31                    title: "many_materials".into(),
32                    present_mode: PresentMode::AutoNoVsync,
33                    ..default()
34                }),
35                ..default()
36            }),
37            FrameTimeDiagnosticsPlugin::default(),
38            LogDiagnosticsPlugin::default(),
39        ))
40        .insert_resource(args)
41        .add_systems(Startup, setup)
42        .add_systems(Update, animate_materials)
43        .run();
44}
Source

pub fn with_scale_factor_override( self, scale_factor_override: f32, ) -> WindowResolution

Builder method for adding a scale factor override to the resolution.

Examples found in repository?
examples/window/scale_factor_override.rs (line 13)
9fn main() {
10    App::new()
11        .add_plugins(DefaultPlugins.set(WindowPlugin {
12            primary_window: Some(Window {
13                resolution: WindowResolution::new(500., 300.).with_scale_factor_override(1.0),
14                ..default()
15            }),
16            ..default()
17        }))
18        .add_systems(Startup, setup)
19        .add_systems(
20            Update,
21            (display_override, toggle_override, change_scale_factor),
22        )
23        .run();
24}
More examples
Hide additional examples
tests/window/resizing.rs (line 26)
20fn main() {
21    App::new()
22        .add_plugins(
23            DefaultPlugins.set(WindowPlugin {
24                primary_window: Some(Window {
25                    resolution: WindowResolution::new(MAX_WIDTH as f32, MAX_HEIGHT as f32)
26                        .with_scale_factor_override(1.0),
27                    title: "Resizing".into(),
28                    ..default()
29                }),
30                ..default()
31            }),
32        )
33        .insert_resource(Dimensions {
34            width: MAX_WIDTH,
35            height: MAX_HEIGHT,
36        })
37        .insert_resource(ContractingY)
38        .add_systems(Startup, (setup_3d, setup_2d))
39        .add_systems(Update, (change_window_size, sync_dimensions))
40        .run();
41}
examples/stress_tests/text_pipeline.rs (line 21)
14fn main() {
15    App::new()
16        .add_plugins((
17            DefaultPlugins.set(WindowPlugin {
18                primary_window: Some(Window {
19                    present_mode: PresentMode::AutoNoVsync,
20                    resolution: WindowResolution::new(1920.0, 1080.0)
21                        .with_scale_factor_override(1.0),
22                    ..default()
23                }),
24                ..default()
25            }),
26            FrameTimeDiagnosticsPlugin::default(),
27            LogDiagnosticsPlugin::default(),
28        ))
29        .insert_resource(WinitSettings {
30            focused_mode: UpdateMode::Continuous,
31            unfocused_mode: UpdateMode::Continuous,
32        })
33        .add_systems(Startup, spawn)
34        .add_systems(Update, update_text_bounds)
35        .run();
36}
examples/ui/text_wrap_debug.rs (line 27)
18fn main() {
19    // `from_env` panics on the web
20    #[cfg(not(target_arch = "wasm32"))]
21    let args: Args = argh::from_env();
22    #[cfg(target_arch = "wasm32")]
23    let args = Args::from_args(&[], &[]).unwrap();
24
25    let window = if let Some(scale_factor) = args.scale_factor {
26        Window {
27            resolution: WindowResolution::default().with_scale_factor_override(scale_factor),
28            ..Default::default()
29        }
30    } else {
31        Window::default()
32    };
33
34    App::new()
35        .add_plugins(DefaultPlugins.set(WindowPlugin {
36            primary_window: Some(window),
37            ..Default::default()
38        }))
39        .insert_resource(WinitSettings::desktop_app())
40        .insert_resource(UiScale(args.ui_scale))
41        .add_systems(Startup, spawn)
42        .run();
43}
examples/stress_tests/many_lights.rs (line 24)
18fn main() {
19    App::new()
20        .add_plugins((
21            DefaultPlugins.set(WindowPlugin {
22                primary_window: Some(Window {
23                    resolution: WindowResolution::new(1920.0, 1080.0)
24                        .with_scale_factor_override(1.0),
25                    title: "many_lights".into(),
26                    present_mode: PresentMode::AutoNoVsync,
27                    ..default()
28                }),
29                ..default()
30            }),
31            FrameTimeDiagnosticsPlugin::default(),
32            LogDiagnosticsPlugin::default(),
33            LogVisibleLights,
34        ))
35        .insert_resource(WinitSettings {
36            focused_mode: UpdateMode::Continuous,
37            unfocused_mode: UpdateMode::Continuous,
38        })
39        .add_systems(Startup, setup)
40        .add_systems(Update, (move_camera, print_light_count))
41        .run();
42}
examples/stress_tests/many_text2d.rs (line 78)
63fn main() {
64    // `from_env` panics on the web
65    #[cfg(not(target_arch = "wasm32"))]
66    let args: Args = argh::from_env();
67    #[cfg(target_arch = "wasm32")]
68    let args = Args::from_args(&[], &[]).unwrap();
69
70    let mut app = App::new();
71
72    app.add_plugins((
73        FrameTimeDiagnosticsPlugin::default(),
74        LogDiagnosticsPlugin::default(),
75        DefaultPlugins.set(WindowPlugin {
76            primary_window: Some(Window {
77                present_mode: PresentMode::AutoNoVsync,
78                resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0),
79                ..default()
80            }),
81            ..default()
82        }),
83    ))
84    .init_resource::<FontHandle>()
85    .add_systems(Startup, setup)
86    .add_systems(Update, (move_camera, print_counts));
87
88    if args.recompute {
89        app.add_systems(Update, recompute);
90    }
91
92    app.insert_resource(args).run();
93}
Source

pub fn width(&self) -> f32

The window’s client area width in logical pixels.

Examples found in repository?
examples/stress_tests/many_cameras_lights.rs (line 60)
24fn setup(
25    mut commands: Commands,
26    mut meshes: ResMut<Assets<Mesh>>,
27    mut materials: ResMut<Assets<StandardMaterial>>,
28    window: Query<&Window>,
29) -> Result {
30    // circular base
31    commands.spawn((
32        Mesh3d(meshes.add(Circle::new(4.0))),
33        MeshMaterial3d(materials.add(Color::WHITE)),
34        Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
35    ));
36
37    // cube
38    commands.spawn((
39        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
40        MeshMaterial3d(materials.add(Color::WHITE)),
41        Transform::from_xyz(0.0, 0.5, 0.0),
42    ));
43
44    // lights
45    for i in 0..NUM_LIGHTS {
46        let angle = (i as f32) / (NUM_LIGHTS as f32) * PI * 2.0;
47        commands.spawn((
48            PointLight {
49                color: Color::hsv(angle.to_degrees(), 1.0, 1.0),
50                intensity: 2_000_000.0 / NUM_LIGHTS as f32,
51                shadows_enabled: true,
52                ..default()
53            },
54            Transform::from_xyz(sin(angle) * 4.0, 2.0, cos(angle) * 4.0),
55        ));
56    }
57
58    // cameras
59    let window = window.single()?;
60    let width = window.resolution.width() / CAMERA_COLS as f32 * window.resolution.scale_factor();
61    let height = window.resolution.height() / CAMERA_ROWS as f32 * window.resolution.scale_factor();
62    let mut i = 0;
63    for y in 0..CAMERA_COLS {
64        for x in 0..CAMERA_ROWS {
65            let angle = i as f32 / (CAMERA_ROWS * CAMERA_COLS) as f32 * PI * 2.0;
66            commands.spawn((
67                Camera3d::default(),
68                Camera {
69                    viewport: Some(Viewport {
70                        physical_position: UVec2::new(
71                            (x as f32 * width) as u32,
72                            (y as f32 * height) as u32,
73                        ),
74                        physical_size: UVec2::new(width as u32, height as u32),
75                        ..default()
76                    }),
77                    order: i,
78                    ..default()
79                },
80                Transform::from_xyz(sin(angle) * 4.0, 2.5, cos(angle) * 4.0)
81                    .looking_at(Vec3::ZERO, Vec3::Y),
82            ));
83            i += 1;
84        }
85    }
86    Ok(())
87}
More examples
Hide additional examples
examples/stress_tests/bevymark.rs (line 402)
392fn spawn_birds(
393    commands: &mut Commands,
394    args: &Args,
395    primary_window_resolution: &WindowResolution,
396    counter: &mut BevyCounter,
397    spawn_count: usize,
398    bird_resources: &mut BirdResources,
399    waves_to_simulate: Option<usize>,
400    wave: usize,
401) {
402    let bird_x = (primary_window_resolution.width() / -2.) + HALF_BIRD_SIZE;
403    let bird_y = (primary_window_resolution.height() / 2.) - HALF_BIRD_SIZE;
404
405    let half_extents = 0.5 * primary_window_resolution.size();
406
407    let color = counter.color;
408    let current_count = counter.count;
409
410    match args.mode {
411        Mode::Sprite => {
412            let batch = (0..spawn_count)
413                .map(|count| {
414                    let bird_z = if args.ordered_z {
415                        (current_count + count) as f32 * 0.00001
416                    } else {
417                        bird_resources.transform_rng.r#gen::<f32>()
418                    };
419
420                    let (transform, velocity) = bird_velocity_transform(
421                        half_extents,
422                        Vec3::new(bird_x, bird_y, bird_z),
423                        &mut bird_resources.velocity_rng,
424                        waves_to_simulate,
425                        FIXED_DELTA_TIME,
426                    );
427
428                    let color = if args.vary_per_instance {
429                        Color::linear_rgb(
430                            bird_resources.color_rng.r#gen(),
431                            bird_resources.color_rng.r#gen(),
432                            bird_resources.color_rng.r#gen(),
433                        )
434                    } else {
435                        color
436                    };
437                    (
438                        Sprite {
439                            image: bird_resources
440                                .textures
441                                .choose(&mut bird_resources.material_rng)
442                                .unwrap()
443                                .clone(),
444                            color,
445                            ..default()
446                        },
447                        transform,
448                        Bird { velocity },
449                    )
450                })
451                .collect::<Vec<_>>();
452            commands.spawn_batch(batch);
453        }
454        Mode::Mesh2d => {
455            let batch = (0..spawn_count)
456                .map(|count| {
457                    let bird_z = if args.ordered_z {
458                        (current_count + count) as f32 * 0.00001
459                    } else {
460                        bird_resources.transform_rng.r#gen::<f32>()
461                    };
462
463                    let (transform, velocity) = bird_velocity_transform(
464                        half_extents,
465                        Vec3::new(bird_x, bird_y, bird_z),
466                        &mut bird_resources.velocity_rng,
467                        waves_to_simulate,
468                        FIXED_DELTA_TIME,
469                    );
470
471                    let material =
472                        if args.vary_per_instance || args.material_texture_count > args.waves {
473                            bird_resources
474                                .materials
475                                .choose(&mut bird_resources.material_rng)
476                                .unwrap()
477                                .clone()
478                        } else {
479                            bird_resources.materials[wave % bird_resources.materials.len()].clone()
480                        };
481                    (
482                        Mesh2d(bird_resources.quad.clone()),
483                        MeshMaterial2d(material),
484                        transform,
485                        Bird { velocity },
486                    )
487                })
488                .collect::<Vec<_>>();
489            commands.spawn_batch(batch);
490        }
491    }
492
493    counter.count += spawn_count;
494    counter.color = Color::linear_rgb(
495        bird_resources.color_rng.r#gen(),
496        bird_resources.color_rng.r#gen(),
497        bird_resources.color_rng.r#gen(),
498    );
499}
Source

pub fn height(&self) -> f32

The window’s client area height in logical pixels.

Examples found in repository?
examples/stress_tests/many_cameras_lights.rs (line 61)
24fn setup(
25    mut commands: Commands,
26    mut meshes: ResMut<Assets<Mesh>>,
27    mut materials: ResMut<Assets<StandardMaterial>>,
28    window: Query<&Window>,
29) -> Result {
30    // circular base
31    commands.spawn((
32        Mesh3d(meshes.add(Circle::new(4.0))),
33        MeshMaterial3d(materials.add(Color::WHITE)),
34        Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
35    ));
36
37    // cube
38    commands.spawn((
39        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
40        MeshMaterial3d(materials.add(Color::WHITE)),
41        Transform::from_xyz(0.0, 0.5, 0.0),
42    ));
43
44    // lights
45    for i in 0..NUM_LIGHTS {
46        let angle = (i as f32) / (NUM_LIGHTS as f32) * PI * 2.0;
47        commands.spawn((
48            PointLight {
49                color: Color::hsv(angle.to_degrees(), 1.0, 1.0),
50                intensity: 2_000_000.0 / NUM_LIGHTS as f32,
51                shadows_enabled: true,
52                ..default()
53            },
54            Transform::from_xyz(sin(angle) * 4.0, 2.0, cos(angle) * 4.0),
55        ));
56    }
57
58    // cameras
59    let window = window.single()?;
60    let width = window.resolution.width() / CAMERA_COLS as f32 * window.resolution.scale_factor();
61    let height = window.resolution.height() / CAMERA_ROWS as f32 * window.resolution.scale_factor();
62    let mut i = 0;
63    for y in 0..CAMERA_COLS {
64        for x in 0..CAMERA_ROWS {
65            let angle = i as f32 / (CAMERA_ROWS * CAMERA_COLS) as f32 * PI * 2.0;
66            commands.spawn((
67                Camera3d::default(),
68                Camera {
69                    viewport: Some(Viewport {
70                        physical_position: UVec2::new(
71                            (x as f32 * width) as u32,
72                            (y as f32 * height) as u32,
73                        ),
74                        physical_size: UVec2::new(width as u32, height as u32),
75                        ..default()
76                    }),
77                    order: i,
78                    ..default()
79                },
80                Transform::from_xyz(sin(angle) * 4.0, 2.5, cos(angle) * 4.0)
81                    .looking_at(Vec3::ZERO, Vec3::Y),
82            ));
83            i += 1;
84        }
85    }
86    Ok(())
87}
More examples
Hide additional examples
examples/stress_tests/bevymark.rs (line 403)
392fn spawn_birds(
393    commands: &mut Commands,
394    args: &Args,
395    primary_window_resolution: &WindowResolution,
396    counter: &mut BevyCounter,
397    spawn_count: usize,
398    bird_resources: &mut BirdResources,
399    waves_to_simulate: Option<usize>,
400    wave: usize,
401) {
402    let bird_x = (primary_window_resolution.width() / -2.) + HALF_BIRD_SIZE;
403    let bird_y = (primary_window_resolution.height() / 2.) - HALF_BIRD_SIZE;
404
405    let half_extents = 0.5 * primary_window_resolution.size();
406
407    let color = counter.color;
408    let current_count = counter.count;
409
410    match args.mode {
411        Mode::Sprite => {
412            let batch = (0..spawn_count)
413                .map(|count| {
414                    let bird_z = if args.ordered_z {
415                        (current_count + count) as f32 * 0.00001
416                    } else {
417                        bird_resources.transform_rng.r#gen::<f32>()
418                    };
419
420                    let (transform, velocity) = bird_velocity_transform(
421                        half_extents,
422                        Vec3::new(bird_x, bird_y, bird_z),
423                        &mut bird_resources.velocity_rng,
424                        waves_to_simulate,
425                        FIXED_DELTA_TIME,
426                    );
427
428                    let color = if args.vary_per_instance {
429                        Color::linear_rgb(
430                            bird_resources.color_rng.r#gen(),
431                            bird_resources.color_rng.r#gen(),
432                            bird_resources.color_rng.r#gen(),
433                        )
434                    } else {
435                        color
436                    };
437                    (
438                        Sprite {
439                            image: bird_resources
440                                .textures
441                                .choose(&mut bird_resources.material_rng)
442                                .unwrap()
443                                .clone(),
444                            color,
445                            ..default()
446                        },
447                        transform,
448                        Bird { velocity },
449                    )
450                })
451                .collect::<Vec<_>>();
452            commands.spawn_batch(batch);
453        }
454        Mode::Mesh2d => {
455            let batch = (0..spawn_count)
456                .map(|count| {
457                    let bird_z = if args.ordered_z {
458                        (current_count + count) as f32 * 0.00001
459                    } else {
460                        bird_resources.transform_rng.r#gen::<f32>()
461                    };
462
463                    let (transform, velocity) = bird_velocity_transform(
464                        half_extents,
465                        Vec3::new(bird_x, bird_y, bird_z),
466                        &mut bird_resources.velocity_rng,
467                        waves_to_simulate,
468                        FIXED_DELTA_TIME,
469                    );
470
471                    let material =
472                        if args.vary_per_instance || args.material_texture_count > args.waves {
473                            bird_resources
474                                .materials
475                                .choose(&mut bird_resources.material_rng)
476                                .unwrap()
477                                .clone()
478                        } else {
479                            bird_resources.materials[wave % bird_resources.materials.len()].clone()
480                        };
481                    (
482                        Mesh2d(bird_resources.quad.clone()),
483                        MeshMaterial2d(material),
484                        transform,
485                        Bird { velocity },
486                    )
487                })
488                .collect::<Vec<_>>();
489            commands.spawn_batch(batch);
490        }
491    }
492
493    counter.count += spawn_count;
494    counter.color = Color::linear_rgb(
495        bird_resources.color_rng.r#gen(),
496        bird_resources.color_rng.r#gen(),
497        bird_resources.color_rng.r#gen(),
498    );
499}
Source

pub fn size(&self) -> Vec2

The window’s client size in logical pixels

Examples found in repository?
examples/stress_tests/bevymark.rs (line 405)
392fn spawn_birds(
393    commands: &mut Commands,
394    args: &Args,
395    primary_window_resolution: &WindowResolution,
396    counter: &mut BevyCounter,
397    spawn_count: usize,
398    bird_resources: &mut BirdResources,
399    waves_to_simulate: Option<usize>,
400    wave: usize,
401) {
402    let bird_x = (primary_window_resolution.width() / -2.) + HALF_BIRD_SIZE;
403    let bird_y = (primary_window_resolution.height() / 2.) - HALF_BIRD_SIZE;
404
405    let half_extents = 0.5 * primary_window_resolution.size();
406
407    let color = counter.color;
408    let current_count = counter.count;
409
410    match args.mode {
411        Mode::Sprite => {
412            let batch = (0..spawn_count)
413                .map(|count| {
414                    let bird_z = if args.ordered_z {
415                        (current_count + count) as f32 * 0.00001
416                    } else {
417                        bird_resources.transform_rng.r#gen::<f32>()
418                    };
419
420                    let (transform, velocity) = bird_velocity_transform(
421                        half_extents,
422                        Vec3::new(bird_x, bird_y, bird_z),
423                        &mut bird_resources.velocity_rng,
424                        waves_to_simulate,
425                        FIXED_DELTA_TIME,
426                    );
427
428                    let color = if args.vary_per_instance {
429                        Color::linear_rgb(
430                            bird_resources.color_rng.r#gen(),
431                            bird_resources.color_rng.r#gen(),
432                            bird_resources.color_rng.r#gen(),
433                        )
434                    } else {
435                        color
436                    };
437                    (
438                        Sprite {
439                            image: bird_resources
440                                .textures
441                                .choose(&mut bird_resources.material_rng)
442                                .unwrap()
443                                .clone(),
444                            color,
445                            ..default()
446                        },
447                        transform,
448                        Bird { velocity },
449                    )
450                })
451                .collect::<Vec<_>>();
452            commands.spawn_batch(batch);
453        }
454        Mode::Mesh2d => {
455            let batch = (0..spawn_count)
456                .map(|count| {
457                    let bird_z = if args.ordered_z {
458                        (current_count + count) as f32 * 0.00001
459                    } else {
460                        bird_resources.transform_rng.r#gen::<f32>()
461                    };
462
463                    let (transform, velocity) = bird_velocity_transform(
464                        half_extents,
465                        Vec3::new(bird_x, bird_y, bird_z),
466                        &mut bird_resources.velocity_rng,
467                        waves_to_simulate,
468                        FIXED_DELTA_TIME,
469                    );
470
471                    let material =
472                        if args.vary_per_instance || args.material_texture_count > args.waves {
473                            bird_resources
474                                .materials
475                                .choose(&mut bird_resources.material_rng)
476                                .unwrap()
477                                .clone()
478                        } else {
479                            bird_resources.materials[wave % bird_resources.materials.len()].clone()
480                        };
481                    (
482                        Mesh2d(bird_resources.quad.clone()),
483                        MeshMaterial2d(material),
484                        transform,
485                        Bird { velocity },
486                    )
487                })
488                .collect::<Vec<_>>();
489            commands.spawn_batch(batch);
490        }
491    }
492
493    counter.count += spawn_count;
494    counter.color = Color::linear_rgb(
495        bird_resources.color_rng.r#gen(),
496        bird_resources.color_rng.r#gen(),
497        bird_resources.color_rng.r#gen(),
498    );
499}
Source

pub fn physical_width(&self) -> u32

The window’s client area width in physical pixels.

Source

pub fn physical_height(&self) -> u32

The window’s client area height in physical pixels.

Source

pub fn physical_size(&self) -> UVec2

The window’s client size in physical pixels

Examples found in repository?
examples/2d/2d_viewport_to_world.rs (line 72)
58fn controls(
59    mut camera_query: Query<(&mut Camera, &mut Transform, &mut Projection)>,
60    window: Query<&Window>,
61    input: Res<ButtonInput<KeyCode>>,
62    time: Res<Time<Fixed>>,
63) {
64    let Ok(window) = window.single() else {
65        return;
66    };
67    let Ok((mut camera, mut transform, mut projection)) = camera_query.single_mut() else {
68        return;
69    };
70    let fspeed = 600.0 * time.delta_secs();
71    let uspeed = fspeed as u32;
72    let window_size = window.resolution.physical_size();
73
74    // Camera movement controls
75    if input.pressed(KeyCode::ArrowUp) {
76        transform.translation.y += fspeed;
77    }
78    if input.pressed(KeyCode::ArrowDown) {
79        transform.translation.y -= fspeed;
80    }
81    if input.pressed(KeyCode::ArrowLeft) {
82        transform.translation.x -= fspeed;
83    }
84    if input.pressed(KeyCode::ArrowRight) {
85        transform.translation.x += fspeed;
86    }
87
88    // Camera zoom controls
89    if let Projection::Orthographic(projection2d) = &mut *projection {
90        if input.pressed(KeyCode::Comma) {
91            projection2d.scale *= powf(4.0f32, time.delta_secs());
92        }
93
94        if input.pressed(KeyCode::Period) {
95            projection2d.scale *= powf(0.25f32, time.delta_secs());
96        }
97    }
98
99    if let Some(viewport) = camera.viewport.as_mut() {
100        // Viewport movement controls
101        if input.pressed(KeyCode::KeyW) {
102            viewport.physical_position.y = viewport.physical_position.y.saturating_sub(uspeed);
103        }
104        if input.pressed(KeyCode::KeyS) {
105            viewport.physical_position.y += uspeed;
106        }
107        if input.pressed(KeyCode::KeyA) {
108            viewport.physical_position.x = viewport.physical_position.x.saturating_sub(uspeed);
109        }
110        if input.pressed(KeyCode::KeyD) {
111            viewport.physical_position.x += uspeed;
112        }
113
114        // Bound viewport position so it doesn't go off-screen
115        viewport.physical_position = viewport
116            .physical_position
117            .min(window_size - viewport.physical_size);
118
119        // Viewport size controls
120        if input.pressed(KeyCode::KeyI) {
121            viewport.physical_size.y = viewport.physical_size.y.saturating_sub(uspeed);
122        }
123        if input.pressed(KeyCode::KeyK) {
124            viewport.physical_size.y += uspeed;
125        }
126        if input.pressed(KeyCode::KeyJ) {
127            viewport.physical_size.x = viewport.physical_size.x.saturating_sub(uspeed);
128        }
129        if input.pressed(KeyCode::KeyL) {
130            viewport.physical_size.x += uspeed;
131        }
132
133        // Bound viewport size so it doesn't go off-screen
134        viewport.physical_size = viewport
135            .physical_size
136            .min(window_size - viewport.physical_position)
137            .max(UVec2::new(20, 20));
138    }
139}
140
141fn setup(
142    mut commands: Commands,
143    mut meshes: ResMut<Assets<Mesh>>,
144    mut materials: ResMut<Assets<ColorMaterial>>,
145    window: Single<&Window>,
146) {
147    let window_size = window.resolution.physical_size().as_vec2();
148
149    // Initialize centered, non-window-filling viewport
150    commands.spawn((
151        Camera2d,
152        Camera {
153            viewport: Some(Viewport {
154                physical_position: (window_size * 0.125).as_uvec2(),
155                physical_size: (window_size * 0.75).as_uvec2(),
156                ..default()
157            }),
158            ..default()
159        },
160    ));
161
162    // Create a minimal UI explaining how to interact with the example
163    commands.spawn((
164        Text::new(
165            "Move the mouse to see the circle follow your cursor.\n\
166                    Use the arrow keys to move the camera.\n\
167                    Use the comma and period keys to zoom in and out.\n\
168                    Use the WASD keys to move the viewport.\n\
169                    Use the IJKL keys to resize the viewport.",
170        ),
171        Node {
172            position_type: PositionType::Absolute,
173            top: Val::Px(12.0),
174            left: Val::Px(12.0),
175            ..default()
176        },
177    ));
178
179    // Add mesh to make camera movement visible
180    commands.spawn((
181        Mesh2d(meshes.add(Rectangle::new(40.0, 20.0))),
182        MeshMaterial2d(materials.add(Color::from(GREEN))),
183    ));
184
185    // Add background to visualize viewport bounds
186    commands.spawn((
187        Mesh2d(meshes.add(Rectangle::new(50000.0, 50000.0))),
188        MeshMaterial2d(materials.add(Color::linear_rgb(0.01, 0.01, 0.01))),
189        Transform::from_translation(Vec3::new(0.0, 0.0, -200.0)),
190    ));
191}
Source

pub fn scale_factor(&self) -> f32

The ratio of physical pixels to logical pixels.

physical_pixels = logical_pixels * scale_factor

Examples found in repository?
examples/stress_tests/many_cameras_lights.rs (line 60)
24fn setup(
25    mut commands: Commands,
26    mut meshes: ResMut<Assets<Mesh>>,
27    mut materials: ResMut<Assets<StandardMaterial>>,
28    window: Query<&Window>,
29) -> Result {
30    // circular base
31    commands.spawn((
32        Mesh3d(meshes.add(Circle::new(4.0))),
33        MeshMaterial3d(materials.add(Color::WHITE)),
34        Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
35    ));
36
37    // cube
38    commands.spawn((
39        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
40        MeshMaterial3d(materials.add(Color::WHITE)),
41        Transform::from_xyz(0.0, 0.5, 0.0),
42    ));
43
44    // lights
45    for i in 0..NUM_LIGHTS {
46        let angle = (i as f32) / (NUM_LIGHTS as f32) * PI * 2.0;
47        commands.spawn((
48            PointLight {
49                color: Color::hsv(angle.to_degrees(), 1.0, 1.0),
50                intensity: 2_000_000.0 / NUM_LIGHTS as f32,
51                shadows_enabled: true,
52                ..default()
53            },
54            Transform::from_xyz(sin(angle) * 4.0, 2.0, cos(angle) * 4.0),
55        ));
56    }
57
58    // cameras
59    let window = window.single()?;
60    let width = window.resolution.width() / CAMERA_COLS as f32 * window.resolution.scale_factor();
61    let height = window.resolution.height() / CAMERA_ROWS as f32 * window.resolution.scale_factor();
62    let mut i = 0;
63    for y in 0..CAMERA_COLS {
64        for x in 0..CAMERA_ROWS {
65            let angle = i as f32 / (CAMERA_ROWS * CAMERA_COLS) as f32 * PI * 2.0;
66            commands.spawn((
67                Camera3d::default(),
68                Camera {
69                    viewport: Some(Viewport {
70                        physical_position: UVec2::new(
71                            (x as f32 * width) as u32,
72                            (y as f32 * height) as u32,
73                        ),
74                        physical_size: UVec2::new(width as u32, height as u32),
75                        ..default()
76                    }),
77                    order: i,
78                    ..default()
79                },
80                Transform::from_xyz(sin(angle) * 4.0, 2.5, cos(angle) * 4.0)
81                    .looking_at(Vec3::ZERO, Vec3::Y),
82            ));
83            i += 1;
84        }
85    }
86    Ok(())
87}
Source

pub fn base_scale_factor(&self) -> f32

The window scale factor as reported by the window backend.

This value is unaffected by WindowResolution::scale_factor_override.

Source

pub fn scale_factor_override(&self) -> Option<f32>

The scale factor set with WindowResolution::set_scale_factor_override.

This value may be different from the scale factor reported by the window backend.

Examples found in repository?
examples/window/scale_factor_override.rs (line 72)
65fn display_override(
66    mut window: Single<&mut Window>,
67    mut custom_text: Single<&mut Text, With<CustomText>>,
68) {
69    let text = format!(
70        "Scale factor: {:.1} {}",
71        window.scale_factor(),
72        if window.resolution.scale_factor_override().is_some() {
73            "(overridden)"
74        } else {
75            "(default)"
76        }
77    );
78
79    window.title.clone_from(&text);
80    custom_text.0 = text;
81}
82
83/// This system toggles scale factor overrides when enter is pressed
84fn toggle_override(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) {
85    if input.just_pressed(KeyCode::Enter) {
86        let scale_factor_override = window.resolution.scale_factor_override();
87        window
88            .resolution
89            .set_scale_factor_override(scale_factor_override.xor(Some(1.0)));
90    }
91}
92
93/// This system changes the scale factor override when up or down is pressed
94fn change_scale_factor(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) {
95    let scale_factor_override = window.resolution.scale_factor_override();
96    if input.just_pressed(KeyCode::ArrowUp) {
97        window
98            .resolution
99            .set_scale_factor_override(scale_factor_override.map(|n| n + 1.0));
100    } else if input.just_pressed(KeyCode::ArrowDown) {
101        window
102            .resolution
103            .set_scale_factor_override(scale_factor_override.map(|n| (n - 1.0).max(1.0)));
104    }
105}
Source

pub fn set(&mut self, width: f32, height: f32)

Set the window’s logical resolution.

Examples found in repository?
tests/window/resizing.rs (line 101)
99fn sync_dimensions(dim: Res<Dimensions>, mut window: Single<&mut Window>) {
100    if dim.is_changed() {
101        window.resolution.set(dim.width as f32, dim.height as f32);
102    }
103}
More examples
Hide additional examples
examples/window/window_resizing.rs (line 61)
54fn toggle_resolution(
55    keys: Res<ButtonInput<KeyCode>>,
56    mut window: Single<&mut Window>,
57    resolution: Res<ResolutionSettings>,
58) {
59    if keys.just_pressed(KeyCode::Digit1) {
60        let res = resolution.small;
61        window.resolution.set(res.x, res.y);
62    }
63    if keys.just_pressed(KeyCode::Digit2) {
64        let res = resolution.medium;
65        window.resolution.set(res.x, res.y);
66    }
67    if keys.just_pressed(KeyCode::Digit3) {
68        let res = resolution.large;
69        window.resolution.set(res.x, res.y);
70    }
71}
Source

pub fn set_physical_resolution(&mut self, width: u32, height: u32)

Set the window’s physical resolution.

This will ignore the scale factor setting, so most of the time you should prefer to use WindowResolution::set.

Source

pub fn set_scale_factor(&mut self, scale_factor: f32)

Set the window’s scale factor, this may get overridden by the backend.

Source

pub fn set_scale_factor_override(&mut self, scale_factor_override: Option<f32>)

Set the window’s scale factor, this will be used over what the backend decides.

This can change the logical and physical sizes if the resulting physical size is not within the limits.

Examples found in repository?
examples/window/scale_factor_override.rs (line 89)
84fn toggle_override(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) {
85    if input.just_pressed(KeyCode::Enter) {
86        let scale_factor_override = window.resolution.scale_factor_override();
87        window
88            .resolution
89            .set_scale_factor_override(scale_factor_override.xor(Some(1.0)));
90    }
91}
92
93/// This system changes the scale factor override when up or down is pressed
94fn change_scale_factor(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) {
95    let scale_factor_override = window.resolution.scale_factor_override();
96    if input.just_pressed(KeyCode::ArrowUp) {
97        window
98            .resolution
99            .set_scale_factor_override(scale_factor_override.map(|n| n + 1.0));
100    } else if input.just_pressed(KeyCode::ArrowDown) {
101        window
102            .resolution
103            .set_scale_factor_override(scale_factor_override.map(|n| (n - 1.0).max(1.0)));
104    }
105}

Trait Implementations§

Source§

impl Clone for WindowResolution

Source§

fn clone(&self) -> WindowResolution

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WindowResolution

Source§

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

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

impl Default for WindowResolution

Source§

fn default() -> WindowResolution

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for WindowResolution

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<WindowResolution, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<I> From<[I; 2]> for WindowResolution
where I: Into<f32>,

Source§

fn from(_: [I; 2]) -> WindowResolution

Converts to this type from the input type.
Source§

impl<I> From<(I, I)> for WindowResolution
where I: Into<f32>,

Source§

fn from(_: (I, I)) -> WindowResolution

Converts to this type from the input type.
Source§

impl From<DVec2> for WindowResolution

Source§

fn from(res: DVec2) -> WindowResolution

Converts to this type from the input type.
Source§

impl From<Vec2> for WindowResolution

Source§

fn from(res: Vec2) -> WindowResolution

Converts to this type from the input type.
Source§

impl FromArg for &'static WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

type This<'from_arg> = &'from_arg WindowResolution

The type to convert into. Read more
Source§

fn from_arg( arg: Arg<'_>, ) -> Result<<&'static WindowResolution as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromArg for &'static mut WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

type This<'from_arg> = &'from_arg mut WindowResolution

The type to convert into. Read more
Source§

fn from_arg( arg: Arg<'_>, ) -> Result<<&'static mut WindowResolution as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromArg for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

type This<'from_arg> = WindowResolution

The type to convert into. Read more
Source§

fn from_arg( arg: Arg<'_>, ) -> Result<<WindowResolution as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromReflect for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<WindowResolution>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetOwnership for &WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetOwnership for &mut WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetOwnership for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetTypeRegistration for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl IntoReturn for &WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where &WindowResolution: 'into_return,

Converts Self into a Return value.
Source§

impl IntoReturn for &mut WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where &mut WindowResolution: 'into_return,

Converts Self into a Return value.
Source§

impl IntoReturn for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where WindowResolution: 'into_return,

Converts Self into a Return value.
Source§

impl PartialEq for WindowResolution

Source§

fn eq(&self, other: &WindowResolution) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialReflect for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<WindowResolution>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn try_into_reflect( self: Box<WindowResolution>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>

Attempts to cast this type to a boxed, fully-reflected value.
Source§

fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>

Attempts to cast this type to a fully-reflected value.
Source§

fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>

Attempts to cast this type to a mutable, fully-reflected value.
Source§

fn into_partial_reflect(self: Box<WindowResolution>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)

Casts this type to a reflected value. Read more
Source§

fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)

Casts this type to a mutable, reflected value. Read more
Source§

fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

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

Debug formatter for the value. Read more
Source§

fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>

Attempts to clone Self using reflection. Read more
Source§

fn apply(&mut self, value: &(dyn PartialReflect + 'static))

Applies a reflected value to this value. Read more
Source§

fn clone_value(&self) -> Box<dyn PartialReflect>

👎Deprecated since 0.16.0: to clone reflected values, prefer using reflect_clone. To convert reflected values to dynamic ones, use to_dynamic.
Clones Self into its dynamic representation. Read more
Source§

fn to_dynamic(&self) -> Box<dyn PartialReflect>

Converts this reflected value into its dynamic representation based on its kind. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Reflect for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

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

Returns the value as a Box<dyn Any>. Read more
Source§

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

Returns the value as a &dyn Any. Read more
Source§

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

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<WindowResolution>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a fully-reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl Serialize for WindowResolution

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Struct for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field named name as a &dyn PartialReflect.
Source§

fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field named name as a &mut dyn PartialReflect.
Source§

fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn PartialReflect.
Source§

fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field with index index as a &mut dyn PartialReflect.
Source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
Source§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
Source§

fn to_dynamic_struct(&self) -> DynamicStruct

Source§

fn clone_dynamic(&self) -> DynamicStruct

👎Deprecated since 0.16.0: use to_dynamic_struct instead
Clones the struct into a DynamicStruct.
Source§

fn get_represented_struct_info(&self) -> Option<&'static StructInfo>

Will return None if TypeInfo is not available.
Source§

impl TypePath for WindowResolution

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
Source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for WindowResolution
where WindowResolution: Any + Send + Sync, u32: FromReflect + TypePath + MaybeTyped + RegisterForReflection, Option<f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection, f32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.
Source§

impl StructuralPartialEq for WindowResolution

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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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<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> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

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

Source§

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

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

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

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

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

Converts &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)

Converts &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 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> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
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> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> DynamicTyped for T
where T: Typed,

Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<S> GetField for S
where S: Struct,

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
Source§

fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
Source§

fn path<'p, T>( &self, path: impl ReflectPath<'p>, ) -> Result<&T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
Source§

fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
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> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

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

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Reflectable for T

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,