Skip to content

SliderPrecision component #20032

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 6 commits into from
Jul 9, 2025
Merged

Conversation

viridia
Copy link
Contributor

@viridia viridia commented Jul 8, 2025

This PR adds a SliderPrecision component that lets you control the rounding when dragging a slider.

Part of #19236

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets and removed C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jul 8, 2025
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

In addition to my other nits, CoreSlider needs breadcrumbs linking to this new component.

@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jul 8, 2025
@alice-i-cecile alice-i-cecile added X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 8, 2025
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 8, 2025
@@ -324,13 +359,16 @@ pub(crate) fn slider_on_drag(
} else {
range.start() + span * 0.5
};
let rounded_value = precision
.map(|prec| prec.round(new_value))
Copy link
Contributor

@ickshonpe ickshonpe Jul 9, 2025

Choose a reason for hiding this comment

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

Need to clamp here, otherwise it can round the value to outside of the slider range

Suggested change
.map(|prec| prec.round(new_value))
.map(|prec| range.clamp(prec.round(new_value)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do this slightly differently, because I don't want to clamp twice.

@@ -257,7 +288,9 @@ pub(crate) fn slider_on_pointer_down(
value.0 + step.0
}
}
TrackClick::Snap => click_val,
TrackClick::Snap => precision
.map(|prec| prec.round(click_val))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.map(|prec| prec.round(click_val))
.map(|prec| range.clamp(prec.round(click_val)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already clamped, see previous lines.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 9, 2025
@alice-i-cecile
Copy link
Member

@viridia ping me when merge conflicts are resolved please :)

@viridia viridia force-pushed the slider_precision branch from 1df0424 to 768051f Compare July 9, 2025 19:44
@viridia
Copy link
Contributor Author

viridia commented Jul 9, 2025

Rebased!

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 9, 2025
Merged via the queue into bevyengine:main with commit f2d2535 Jul 9, 2025
32 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-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants