mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 23:24:44 +00:00
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
1 changed files with 8 additions and 5 deletions
|
@ -18,7 +18,7 @@ use bevy_ecs::{
|
|||
system::{Commands, Query, Res, ResMut, Resource},
|
||||
};
|
||||
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::FromReflect;
|
||||
use bevy_transform::components::GlobalTransform;
|
||||
|
@ -156,13 +156,16 @@ impl Camera {
|
|||
Some((min, max))
|
||||
}
|
||||
|
||||
/// The rendered logical bounds (minimum, maximum) of the camera. If the `viewport` field is set
|
||||
/// to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
|
||||
/// The rendered logical bounds [`Rect`] of the camera. If the `viewport` field is set to
|
||||
/// [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
|
||||
/// full logical rect of the current [`RenderTarget`].
|
||||
#[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()?;
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue