Modified scene.show to calculate the mouse position inside the scene, and created an example scene_circle_painter to demonstrate a usecase #7149
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.
Features/changes added
I have modified egui/crates/egui/src/containers/scene.rs, to now also calculate the mouse position inside the scene, dependent on both translation and scale. This has been accomplished by having scene.show also have a mutable borrow of a mouse_position as input, and using the to_global variable inside the show function to calculate the scene mouse position.
Along with this, I have created an example called scene_circle_placer to demonstrate a use case, and have fixed errors that appeared in crates/egui_demo_lib/src/demo/scene.rs due to the change.
Reason
Currently, there is no intuitive way of getting the position of the mouse inside of the scene. It has been possible for me to find the position using the scene response, but the position is not correct when hovering over other interactive elements, such as buttons, making it difficult to create for example dragging behavior of drawn elements.
Issues fixed with this PR
#7060
Note
Due to the nature of the mouse position, I have not been able to find a way to avoid using unwrap, however, I have been very careful not to create any unaccounted situations.
Cargo fmt and cargo clippy has been run successfully.
The command UPDATE_SNAPSHOTS=true cargo test --workspace --all-features was run successfully, and this was the output from ./scripts/check.sh