Skip to content

fix: allow overlay mouse interaction outside its bounds#2921

Merged
hecrj merged 2 commits intoiced-rs:masterfrom
alex-ds13:overlay-interaction-outside-bounds
May 2, 2025
Merged

fix: allow overlay mouse interaction outside its bounds#2921
hecrj merged 2 commits intoiced-rs:masterfrom
alex-ds13:overlay-interaction-outside-bounds

Conversation

@alex-ds13
Copy link
Contributor

This change is related to this discussion on Discord.

This PR changes the overlay's mouse_interaction so that it can still call this function for all open overlays even if the mouse is not over the overlay bounds. This is useful when implementing any sort of drag ability on a widget on an overlay.

Currently if you try to have a widget like a slider that sets the mouse_interaction to Interaction::Grabbing when dragging the slider, this cursor wouldn't show as grabbing if you moved the mouse outside the overlay bounds while dragging. This doesn't seem to be the expected behavior, at lest not to me. I would expect the slider to keep moving and showing the correct cursor while I'm dragging it even if I move the mouse outside the overlay bounds. This PR fixes this.

The issue was that the mouse_interaction function wasn't even being called on an overlay if the mouse was outside it's borders. And even if it was there was still some code on the user_interface.draw() function that wouldn't let you have the overlay_interaction if the mouse wasn't over its bounds.

The core team is busy and does not have time to mentor nor babysit new contributors. If a member of the core team thinks that reviewing and understanding your work will take more time and effort than writing it from scratch by themselves, your contribution will be dismissed. It is your responsibility to communicate and figure out how to reduce the likelihood of this!

Read the contributing guidelines for more details: https://github.com/iced-rs/iced/blob/master/CONTRIBUTING.md

alex-ds13 and others added 2 commits May 2, 2025 15:51
The `mouse_interaction` method can be properly used
now to encode hover status with the `None` and `Idle`
variants.
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just got rid of Overlay::is_over altogether, since mouse_interaction can already be used to encode "hoveredness" thanks to the None and Idle distinction.

Hopefully this didn't break much stuff.

Thanks!

@hecrj hecrj added this to the 0.14 milestone May 2, 2025
@hecrj hecrj added bug Something isn't working improvement An internal improvement widget layout shell fix labels May 2, 2025
@hecrj hecrj merged commit 89ba5f9 into iced-rs:master May 2, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix improvement An internal improvement layout shell widget

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants