-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add scroll functionality to bevy_picking #17704
Add scroll functionality to bevy_picking #17704
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add
.add_event::<Pointer<Scroll>>()
to InteractionPlugin
's Plugin
impl, otherwise you get a panic because it can't find the scroll event resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, thank you!
Objective
bevy_picking
currently 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!