Changed (Vec2, Vec2) to Rect in Camera::logical_viewport_rect (#7867)
# Objective
`Camera::logical_viewport_rect()` returns `Option<(Vec2, Vec2)>` which
is a tuple of vectors representing the `(min, max)` bounds of the
viewport rect. Since the function says it returns a rect and there is a
`Rect { min, max }` struct in `bevy_math`, using the struct will be
clearer.
## Solution
Replaced `Option<(Vec2, Vec2)>` with `Option<Rect>` for
`Camera::logical_viewport_rect()`.
---
## Changelog
- Changed `Camera::logical_viewport_rect` return type from `(Vec2,
Vec2)` to `Rect`
## Migration Guide
Before:
```
fn view_logical_camera_rect(camera_query: Query<&Camera>) {
let camera = camera_query.single();
let Some((min, max)) = camera.logical_viewport_rect() else { return };
dbg!(min, max);
}
```
After:
```
fn view_logical_camera_rect(camera_query: Query<&Camera>) {
let camera = camera_query.single();
let Some(Rect { min, max }) = camera.logical_viewport_rect() else { return };
dbg!(min, max);
}
```
This commit is contained in:
parent
b5d24d8fb2
commit
288009ab8b
@ -18,7 +18,7 @@ use bevy_ecs::{
|
|||||||
system::{Commands, Query, Res, ResMut, Resource},
|
system::{Commands, Query, Res, ResMut, Resource},
|
||||||
};
|
};
|
||||||
use bevy_log::warn;
|
use bevy_log::warn;
|
||||||
use bevy_math::{Mat4, Ray, UVec2, UVec4, Vec2, Vec3};
|
use bevy_math::{Mat4, Ray, Rect, UVec2, UVec4, Vec2, Vec3};
|
||||||
use bevy_reflect::prelude::*;
|
use bevy_reflect::prelude::*;
|
||||||
use bevy_reflect::FromReflect;
|
use bevy_reflect::FromReflect;
|
||||||
use bevy_transform::components::GlobalTransform;
|
use bevy_transform::components::GlobalTransform;
|
||||||
@ -156,13 +156,16 @@ impl Camera {
|
|||||||
Some((min, max))
|
Some((min, max))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The rendered logical bounds (minimum, maximum) of the camera. If the `viewport` field is set
|
/// The rendered logical bounds [`Rect`] of the camera. If the `viewport` field is set to
|
||||||
/// to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
|
/// [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
|
||||||
/// full logical rect of the current [`RenderTarget`].
|
/// full logical rect of the current [`RenderTarget`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)> {
|
pub fn logical_viewport_rect(&self) -> Option<Rect> {
|
||||||
let (min, max) = self.physical_viewport_rect()?;
|
let (min, max) = self.physical_viewport_rect()?;
|
||||||
Some((self.to_logical(min)?, self.to_logical(max)?))
|
Some(Rect {
|
||||||
|
min: self.to_logical(min)?,
|
||||||
|
max: self.to_logical(max)?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The logical size of this camera's viewport. If the `viewport` field is set to [`Some`], this
|
/// The logical size of this camera's viewport. If the `viewport` field is set to [`Some`], this
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user