-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add drag and drop picking example #22214
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
base: main
Are you sure you want to change the base?
Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Hilpogar
left a comment
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.
I think the example isn't very intuitive for someone discovering it for the first time. Replacing the red dot with a box containing "Drag from me" and adding a text in the green arena with "Drop here" could improve the example while keeping the code minimalist.
2368dc8 to
1da3114
Compare
Done! Added screenshot to PR desc |
Hilpogar
left a comment
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.
Perfect 👍
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.
Just got a few minor suggestions, but otherwise looks good.
| )) | ||
| .observe(on_drag_enter) | ||
| .observe(on_drag_over) | ||
| .observe(on_drag_drop) | ||
| .observe(on_drag_leave); | ||
|
|
||
| commands.spawn(( | ||
| Text2d::new("Drop here"), | ||
| TextColor(Color::WHITE), | ||
| Pickable::IGNORE, | ||
| )); |
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.
I think it's more natural for the label to be a child of the DropArea entity, and the z-ordering of elements here isn't guaranteed even though in practice it normally renders in the order the entities were spawned.
| )) | |
| .observe(on_drag_enter) | |
| .observe(on_drag_over) | |
| .observe(on_drag_drop) | |
| .observe(on_drag_leave); | |
| commands.spawn(( | |
| Text2d::new("Drop here"), | |
| TextColor(Color::WHITE), | |
| Pickable::IGNORE, | |
| )); | |
| children![( | |
| Text2d::new("Drop here"), | |
| TextFont::from_font_size(50.), | |
| TextColor(Color::BLACK), | |
| Pickable::IGNORE, | |
| Transform::from_translation(Vec3::Z), | |
| )], | |
| )) | |
| .observe(on_drag_enter) | |
| .observe(on_drag_over) | |
| .observe(on_drag_drop) | |
| .observe(on_drag_leave); |
| GhostPreview, | ||
| Mesh2d(meshes.add(Circle::new(ELEMENT_SIZE))), | ||
| MeshMaterial2d(materials.add(Color::srgba(1.0, 1.0, 0.6, 0.5))), | ||
| Transform::from_translation(position), |
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.
| Transform::from_translation(position), | |
| Transform::from_translation(position + 2. * Vec3::Z), |
| DroppedElement, | ||
| Mesh2d(meshes.add(Circle::new(ELEMENT_SIZE))), | ||
| MeshMaterial2d(materials.add(Color::srgb(1.0, 1.0, 0.6))), | ||
| Transform::from_translation(position), |
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.
| Transform::from_translation(position), | |
| Transform::from_translation(position + 2. * Vec3::Z), |
Objective
Fixes #21894
Solution
As suggested in the issue adds the drag drop example from #21849 to the picking examples.
Testing
Change is trivial, adding an example so simply ran, and checked it matched the expected behaviour
Showcase