Add scroll functionality to bevy_picking#17704
Merged
alice-i-cecile merged 6 commits intobevyengine:mainfrom Feb 10, 2025
Merged
Add scroll functionality to bevy_picking#17704alice-i-cecile merged 6 commits intobevyengine:mainfrom
alice-i-cecile merged 6 commits intobevyengine:mainfrom
Conversation
aevyrie
reviewed
Feb 6, 2025
ickshonpe
reviewed
Feb 6, 2025
ickshonpe
reviewed
Feb 6, 2025
Contributor
There was a problem hiding this comment.
With the event registered, there don't seem to be any other problems.
To test the changes, I removed the update_scroll_position from the testbed_ui example (in examples/testbed/ui.rs) and added an observer to the scrollable node:
// Scrolling list
parent
.spawn((
Node {
flex_direction: FlexDirection::Column,
align_self: AlignSelf::Stretch,
height: Val::Percent(50.),
overflow: Overflow::scroll_y(),
..default()
},
BackgroundColor(Color::srgb(0.10, 0.10, 0.10)),
))
.observe(|
trigger: Trigger<Pointer<Scroll>>,
mut scroll_position_query: Query<&mut ScrollPosition>,
| {
if let Ok(mut scroll_position) = scroll_position_query.get_mut(trigger.target) {
let (dx, dy) = match trigger.unit {
MouseScrollUnit::Line => (trigger.x * 20., trigger.y * 20.),
MouseScrollUnit::Pixel => (trigger.x, trigger.y),
};
scroll_position.offset_x -= dx;
scroll_position.offset_y -= dy;
}
})
.with_children(|parent| {
// List items
for i in 0..25 {
parent
.spawn((
Text(format!("Item {i}")),
TextFont {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
..default()
},
Label,
AccessibilityNode(Accessible::new(Role::ListItem)),
))
.insert(Pickable {
should_block_lower: false,
..default()
});
}
});scrolling working as before.
ickshonpe
reviewed
Feb 6, 2025
Contributor
Author
Done! |
ickshonpe
approved these changes
Feb 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
bevy_pickingcurrently does not support scroll events.Solution
This pr adds a new event type for scroll, and updates the default input system for mouse pointers to read and emit this event.
Testing
I haven't tested these changes, if the reviewers can advise me how to do so I'd appreciate it!