bevyengine / bevyengine/bevy

Wrong Ui Node Position when using Val::Percent with bigger UiScale

Open
#11,565 0 comments 0 reactions 0 assignees View on GitHub
A-UI C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

[886a256](https://github.com/bevyengine/bevy/commit/886a2560d24ac248776eea11afabaccfbafa58f4)

## What you did
Spawned a NodeBundle with some values based on Percent.
```rust
commands.spawn(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
height: Val::Percent(50.),
width: Val::Percent(50.),
right: Val::Percent(0.),
..Default::default()
},
background_color: BackgroundColor(Color::WHITE),
..Default::default()
});
```

## What went wrong

The size is not as expected, for example, if I have `Style::right` as `Val::Percent(0.)`, I expect that the Node were in the border of the window

Result images with different `UiScale` (The number at the bottom is the actual scale)

![image](https://github.com/bevyengine/bevy/assets/126117294/f33222b3-c73a-4f00-82a4-528a4d8da497)
![image](https://github.com/bevyengine/bevy/assets/126117294/b08a0661-c015-48fb-9215-348e610033d8)
![image](https://github.com/bevyengine/bevy/assets/126117294/415d8f48-5d68-429f-96d4-a6057c088a8f)
![image](https://github.com/bevyengine/bevy/assets/126117294/05d66474-bf9a-40de-9671-bdf73c84a7ae)

## Additional information

This is related to how the `ui_layout_system` round the Positions, together with the fact that the `Camera` is also transformed by the scale, causes a situation where the rounding causes big gaps.
Also related to #11207

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.