|
2 | 2 |
|
3 | 3 | use crate::{ |
4 | 4 | widget::{Button, ImageMode}, |
5 | | - CalculatedSize, FocusPolicy, Interaction, Node, Style, UiColor, UiImage, |
| 5 | + CalculatedSize, FocusPolicy, Interaction, Node, Style, UiColor, UiImage, UI_CAMERA_FAR, |
6 | 6 | }; |
7 | 7 | use bevy_ecs::{bundle::Bundle, prelude::Component}; |
| 8 | +use bevy_math::Vec2; |
8 | 9 | use bevy_render::{ |
| 10 | + camera::{DepthCalculation, OrthographicProjection, WindowOrigin}, |
9 | 11 | prelude::ComputedVisibility, |
10 | 12 | view::{RenderLayers, Visibility}, |
11 | 13 | }; |
@@ -186,13 +188,42 @@ pub struct UiCameraConfig { |
186 | 188 | pub show_ui: bool, |
187 | 189 | /// The ui camera layers this camera can see. |
188 | 190 | pub ui_render_layers: RenderLayers, |
| 191 | + /// The position of the UI camera in UI space. |
| 192 | + pub position: Vec2, |
| 193 | + /// The projection data for the UI camera. |
| 194 | + /// |
| 195 | + /// The code relies on this not being set, |
| 196 | + /// please use [`UiCameraConfig::scale_mut`] and [`UiCameraConfig::projection`] |
| 197 | + /// instead. |
| 198 | + /// This is only public so it is possible to use the struct update syntax. |
| 199 | + #[doc(hidden)] |
| 200 | + pub projection: OrthographicProjection, |
| 201 | +} |
| 202 | + |
| 203 | +impl UiCameraConfig { |
| 204 | + /// Get mutably the scale of the UI camera, useful for zoom effects. |
| 205 | + pub fn scale_mut(&mut self) -> &mut f32 { |
| 206 | + &mut self.projection.scale |
| 207 | + } |
| 208 | + |
| 209 | + /// The projection data for the UI camera. |
| 210 | + pub fn projection(&self) -> &OrthographicProjection { |
| 211 | + &self.projection |
| 212 | + } |
189 | 213 | } |
190 | 214 |
|
191 | 215 | impl Default for UiCameraConfig { |
192 | 216 | fn default() -> Self { |
193 | 217 | Self { |
194 | 218 | show_ui: true, |
195 | 219 | ui_render_layers: Default::default(), |
| 220 | + position: Vec2::ZERO, |
| 221 | + projection: OrthographicProjection { |
| 222 | + far: UI_CAMERA_FAR, |
| 223 | + window_origin: WindowOrigin::BottomLeft, |
| 224 | + depth_calculation: DepthCalculation::ZDifference, |
| 225 | + ..Default::default() |
| 226 | + }, |
196 | 227 | } |
197 | 228 | } |
198 | 229 | } |
0 commit comments