Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
  • Loading branch information
LoipesMas and alice-i-cecile committed Jul 4, 2022
1 parent 911b930 commit 359c6b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<UVec2>) -> Option<UVec2> {
pub fn try_as_absolute(&self, of_opt: Option<UVec2>) -> Option<UVec2> {
match self {
AbsOrPercVec::Absolute(v) => Some(*v),
AbsOrPercVec::Percentage(_) => of_opt.map(|of| self.as_absolute(of)),
Expand Down Expand Up @@ -159,7 +160,7 @@ impl Camera {
pub fn viewport_absolute_size(&self) -> Option<UVec2> {
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
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/render_phase/draw_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
);
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/split_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 359c6b4

Please sign in to comment.