Add vertical slider support to bevy_ui_widgets slider #21827
+63
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Solution
The slider widget now automatically detects its orientation based on the node's dimensions (
height > widthfor vertical, otherwise horizontal) and adjusts its interaction behavior accordingly:Orientation Detection: Added automatic detection of slider orientation by comparing
node.size().ytonode.size().xin bothslider_on_pointer_downandslider_on_dragfunctions.Drag Direction Fix:
distance.y) instead of X-axisthumb.size().yfor vertical sliders instead of always usingthumb.size().xClick Position Fix:
local_pos.yfrom[-height/2, +height/2]to[0, height]before calculating the slider valueTrack Size Calculation: Uses
node.size().y - thumb_sizefor vertical sliders andnode.size().x - thumb_sizefor horizontal sliders when calculating the available track space.The changes are backward compatible - horizontal sliders continue to work exactly as before, and the orientation detection is transparent to users of the API.
Testing
Manual Testing: Created test application with both vertical and horizontal sliders to verify:
Edge Cases Tested:
Areas that may need more testing:
How reviewers can test:
Platforms tested:
Showcase
Before
before.mov
After
after.mov
Code Example
The orientation is automatically detected based on the node dimensions - no API changes required!