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
Replace using global mouse position with known position for context menus, dropdown menus and tooltips #437
Replace using global mouse position with known position for context menus, dropdown menus and tooltips #437
Conversation
bec5536
to
735e32a
Compare
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/DesktopPopup.desktop.kt
Outdated
Show resolved
Hide resolved
...foundation/src/desktopMain/kotlin/androidx/compose/foundation/ContextMenuProvider.desktop.kt
Outdated
Show resolved
Hide resolved
...foundation/src/desktopMain/kotlin/androidx/compose/foundation/ContextMenuProvider.desktop.kt
Show resolved
Hide resolved
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.
One test fails on CI now. It doesn't seem related, but anyway - please check this
It's unrelated, but I'm looking at it separately. |
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.
Awesome PR! I just provided some comments, please take a look
...foundation/src/desktopMain/kotlin/androidx/compose/foundation/ContextMenuProvider.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/DesktopPopup.desktop.kt
Outdated
Show resolved
Hide resolved
...ndation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/TooltipArea.desktop.kt
Outdated
Show resolved
Hide resolved
...ndation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/TooltipArea.desktop.kt
Outdated
Show resolved
Hide resolved
...foundation/src/desktopMain/kotlin/androidx/compose/foundation/ContextMenuProvider.desktop.kt
Outdated
Show resolved
Hide resolved
6047887
to
f232717
Compare
...ndation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/TooltipArea.desktop.kt
Outdated
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...foundation/src/desktopMain/kotlin/androidx/compose/foundation/ContextMenuProvider.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Outdated
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Outdated
Show resolved
Hide resolved
27a5bac
to
22559d6
Compare
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.
Thanks! It makes API significantly better.
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
...se/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopMenu.desktop.kt
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/DesktopPopup.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/DesktopPopup.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/DesktopPopup.desktop.kt
Outdated
Show resolved
Hide resolved
…enus, dropdown menus and tooltips.
f232717
to
720e011
Compare
and made it a public, experimental API.
I've also renamed |
We are currently using
rememberCursorPositionProvider
, and through it, the global mouse position state in three places:DefaultContextMenuRepresentation
CursorDropdownMenu
.TooltipPlacement.CursorPoint
We would like to instead use the position of the mouse event that triggered the displaying of each of these.
Proposed Changes
DefaultContextMenuRepresentation
, simply use therect
in theContextMenuState.Status.Open
it already has available. The modifier that changes the status toOpen
already places the mouse cursor position there.CursorDropdownMenu
:DropdownMenuState
, a new state class, similar toContextMenuState
. Instead of aRect
, it will hold anIntOffset
.DropdownMenu
overload that will take aDropdownMenuState
and be controlled by it.Modifier.contextMenuOpenDetector(DropdownMenuState)
that detects right-clicks and sets thestate.status
toOpen(cursorPosition)
.DropdownMenu
andcontextMenuOpenDetector
together with state hoisting to display the dropdown menu (example code below).TooltipArea
:TooltipPlacement.positionProvider(cursorPosition: IntOffset)
and haveTooltipArea
provide the cursor position to it when it wants to show the tooltip.TooltipPlacement.CursorPoint
will use the new cursor position argument to position the tooltip popup.Added utilities:
PopupPositionProviderAtOffset
that takes all the necessary arguments to position the popup.PopupPositionProviderAtOffset
from bothrememberCursorPositionProvider
and from a newpopupPositionProviderAtPosition
method.Modifier.contextMenuOpenDetector(onOpen)
andModifier.contextMenuOpenDetector(DropdownMenuState)
Example use of
DropdownMenu
:Testing
Test: Manual testing