Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run stretch's layout on physical coordinates to fix pixel alignment #1061

Merged
merged 2 commits into from
Dec 15, 2020

Conversation

blunted2night
Copy link
Contributor

Currently, the values passed to stretch's algorithm are in logical coordinates. Due to internal rounding in stretch's algorithm, the results don't align to the pixel grid on high DPI monitors with non-integer scaling factors. This patch converts those values to physical coordinates prior to invoking the stretch and converts the results back to logical coordinates so that stretch rounds coordinates to the nearest physical pixel.

@Moxinilian Moxinilian added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets labels Dec 15, 2020
Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I can't produce any artifacts on 2x scale factors (presumably because its a whole number). I guess I'll just trust that this works :)

crates/bevy_ui/src/flex/mod.rs Outdated Show resolved Hide resolved
@blunted2night
Copy link
Contributor Author

There is one artifact you can see when running a 2x scale factor. Run the UI example and watch the two elements anchored to the top edge while resizing the window from the bottom edge. They vibrate vertically due to the fractional part of logical size spinning through different values. For 2x, it would toggle between .0 and .5 which causes the items to move up and down by one pixel.

@cart
Copy link
Member

cart commented Dec 15, 2020

Ooh yeah thats definitely noticeable. And this pr definitely fixes it. Nice work!

@cart cart merged commit 51650f1 into bevyengine:master Dec 15, 2020
@blunted2night blunted2night deleted the flex-pixel-grid branch December 18, 2020 23:47
@mockersf mockersf mentioned this pull request Dec 20, 2020
@fopsdev fopsdev mentioned this pull request Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants