Skip to content

slider widget track click position UiScale fix #19676

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

Merged
merged 2 commits into from
Jun 16, 2025

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Jun 16, 2025

Objective

The position for track clicks in core_slider is calculated incorrectly when using UiScale.

Solution

trigger.event().pointer_location.position uses logical window coordinates, that is:

position = physical_position / window_scale_factor

while ComputedNodeTarget::scale_factor returns the window scale factor multiplied by Ui Scale:

target_scale_factor = window_scale_factor * ui_scale

So to get the physical position need to divide by the UiScale:

position * target_scale_factor / ui_scale
= (physical_postion / window_scale_factor) * (window_scale_factor * ui_scale) / ui_scale
=  physical_position

I thought this was fixed during the slider PR review, but must have got missed somewhere or lost in a merge.

Testing

Can test using the core_widgets examplewith.insert_resource(UiScale(2.))` added to the bevy app.

`trigger.event().pointer_location.position` uses logical window coordinates:
`position = physical_position / window_scale_factor`

while `ComputedNodeTarget::scale_factor` returns the window scale factor multiplied by Ui Scale.

`target_scale_factor = window_scale_factor * ui_scale`

So to get the physical position needs:

```
position * target_scale_factor / ui_scale
= (physical_postion / window_scale_factor) * (window_scale_factor * ui_scale) / ui_scale
=  physical_position
```
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy A-UI Graphical user interfaces, styles, layouts, and widgets S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jun 16, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 16, 2025
Merged via the queue into bevyengine:main with commit c0fa10b Jun 16, 2025
40 checks passed
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 D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants