Ui root node is not sized properly with custom UiCamera's projection
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
0.5
## Operating system & version
Tested on Linux, but probably affects all other systems
## What you did
I have this system that resizes for all the cameras with ```OrthographicsProjection``` and ```CameraAspectRatio``` compoents:
```Rust
pub enum CameraAspectRatio {
Auto {
min_width: f32,
min_height: f32,
},
FixedWidth(f32),
FixedHeight(f32),
}
pub fn camera_aspect_ratio(
windows: Res,
mut query:
Query<(&mut OrthographicProjection, &Camera, &CameraAspectRatio)>,
) {
for (mut projection, camera, ratio) in query.iter_mut() {
if let (ScalingMode::None, Some(window)) =
(&projection.scaling_mode, windows.get(camera.window))
{
let window_size = Vec2::new(window.width(), window.height());
let size = match *ratio {
CameraAspectRatio::Auto { min_width, min_height } => if
window_size.x / window_size.y > min_width / min_height
{
Vec2::new(
min_height * window_size.x / window_size.y,
min_height,
)
} else {
Vec2::new(
min_width, min_width * window_size.y / window_size.x,
)
},
CameraAspectRatio::FixedWidth(width) => Vec2::new(
width,
width * window_size.y / window_size.x,
),
CameraAspectRatio::FixedHeight(height) => Vec2::new(
height * window_size.x / window_size.y,
height,
),
};
match projection.window_origin {
WindowOrigin::Center => {
projection.left = -size.x / 2.0;
projection.right = size.x / 2.0;
projection.bottom = -size.y / 2.0;
projection.top = size.y / 2.0;
},
WindowOrigin::BottomLeft => {
projection.left = 0.0;
projection.right = size.x;
projection.bottom = 0.0;
projection.top = size.y;
},
}
}
}
}
```
The system works fine and the game itself displays correctly. However when I try to create a root node with size set to 100% by 100% it does not fill the whole window, but instead its virtual size gets limited to the value of the real screen size:
```Rust
commands
.spawn_bundle(NodeBundle {
material: materials.add(Color::rgba(1.0, 1.0, 1.0, 0.5).into()),
style: Style {
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
flex_direction: FlexDirection::Row,
align_items: AlignItems::FlexEnd,
justify_content: JustifyContent::SpaceBetween,
..Default::default()
},
..Default::default()
})
```

## What you expected to happen
The root node should fill the whole window.
## What actually happened
The root node's size was limited to the window's logical size and was not enough to fill the virtual camera size (1920 by 1080)
Contributor guide
Research direction
Start by reproducing the issue with the shown camera_aspect_ratio system and NodeBundle root-node setup. Compare the UI root sizing against the custom OrthographicProjection and logical window size; done means a 100% by 100% root node fills the virtual camera size rather than the physical window size.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100