diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index fd2a6cb54d828..3f8134f3ac54a 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -61,7 +61,7 @@ impl Default for AbsOrPercVec { } impl AbsOrPercVec { - /// Returns percentage of provided vec or absolute value from self. + /// Converts this size into a absolute size in pixels. #[inline] pub fn as_absolute(&self, of: UVec2) -> UVec2 { match self { @@ -70,10 +70,11 @@ impl AbsOrPercVec { } } - /// Returns percentage of provided vec or absolute value. + /// Converts this size into a absolute size in pixels if possible. + /// Returns `None` if self is `Percentage` and argument is `None` #[inline] - pub fn as_absolute_opt(&self, of_opt: Option) -> Option { + pub fn try_as_absolute(&self, of_opt: Option) -> Option { match self { AbsOrPercVec::Absolute(v) => Some(*v), AbsOrPercVec::Percentage(_) => of_opt.map(|of| self.as_absolute(of)), @@ -159,7 +160,7 @@ impl Camera { pub fn viewport_absolute_size(&self) -> Option { self.viewport .as_ref() - .and_then(|v| v.physical_size.as_absolute_opt(self.physical_target_size())) + .and_then(|v| v.physical_size.try_as_absolute(self.physical_target_size())) } /// The rendered physical bounds (minimum, maximum) of the camera. If the `viewport` field is diff --git a/crates/bevy_render/src/render_phase/draw_state.rs b/crates/bevy_render/src/render_phase/draw_state.rs index 4a9c0909a8bf3..26faaa32bbde9 100644 --- a/crates/bevy_render/src/render_phase/draw_state.rs +++ b/crates/bevy_render/src/render_phase/draw_state.rs @@ -343,12 +343,12 @@ impl<'a> TrackedRenderPass<'a> { pub fn set_camera_viewport(&mut self, viewport: &Viewport, camera: &ExtractedCamera) { let physical_size = viewport .physical_size - .as_absolute_opt(camera.physical_target_size) + .try_as_absolute(camera.physical_target_size) .expect("Couldn't get camera.physical_target_size (needed for relative viewport size)"); let physical_position = viewport .physical_position - .as_absolute_opt(camera.physical_target_size) + .try_as_absolute(camera.physical_target_size) .expect( "Couldn't get camera.physical_target_size (needed for relative viewport position)", ); diff --git a/examples/3d/split_screen.rs b/examples/3d/split_screen.rs index 8edded7a106e5..9bd36343ef699 100644 --- a/examples/3d/split_screen.rs +++ b/examples/3d/split_screen.rs @@ -107,7 +107,7 @@ fn set_camera_viewports( let mut right_camera = right_camera.single_mut(); right_camera.viewport = Some(Viewport { - // ... or specify a percentage of the render target. + // ... or specify an adaptive percentage of the render target. physical_position: AbsOrPercVec::Percentage(Vec2::new(0.5, 0.0)), physical_size: AbsOrPercVec::Percentage(Vec2::new(0.5, 1.0)), ..default()