Conversation
|
I personally always use a implementation based on observers, and think this should be done that way as well (alongside the scroll) The issue is that a very common and useful pattern is to use picking observers like |
|
I prefer the observers-based design from @laundmo as well: // assuming 1 window
fn setup(mut commands: Commands, window: Single<Entity, With<Window>>) {
commands.entity(*window).observe(camera_drag);
}
fn camera_drag(
drag: On<Pointer<Drag>>,
mut cam: Single<(&Camera, &GlobalTransform, &mut Transform)>,
) {
if let Ok(cam_viewport) = cam.0.world_to_viewport(cam.1, cam.2.translation)
&& let cam_viewport = cam_viewport + drag.delta * -1. // inverted feels more natural
&& let Ok(world_changed) = cam.0.viewport_to_world_2d(cam.1, cam_viewport)
{
cam.2.translation = world_changed.extend(cam.2.translation.z);
}
}I think this is going to be easier to adapt and handle. |
| } | ||
|
|
||
| /// Settings for mouse panning for the [`PanCamera`] controller. | ||
| pub struct MousePanSettings { |
There was a problem hiding this comment.
This needs an enabled bool as well.
| /// [`KeyCode`] for clockwise rotation. | ||
| pub key_rotate_cw: Option<KeyCode>, | ||
| /// Mouse pan settings. | ||
| pub mouse_pan_settings: Option<MousePanSettings>, |
There was a problem hiding this comment.
IMO the use of an Option here isn't very clear. Making this always present but having an enabled bool feels more reasonable.
Objective
The current PanCamera only supports keyboard panning, when a common use case is mouse panning.
Solution
Add optional mouse panning with some settings
Testing
I ran the Pan Camera example with the new settings
Additional notes
I added settings for setting the exact mouse button that triggers the panning, and whether or not to grab the cursor when panning.
I am unsure about the cursor grab part of this design as it may mess with the app's existing cursor options and the window part may not work for some setups.
It may be wiser to just omit grabbing for now, or maybe keep grabbing but don't change visibility idk
As always I am open to any and all feedback.