MatthiasMeger
04/17/2023, 1:36 PMLucas
04/17/2023, 1:55 PMMatthiasMeger
04/17/2023, 9:49 PM.onPointerEvent(PointerEventType.Press) { clicked(item, it) }
In "clicked" I check which mouse button was pressed and which keys (pointerEvent.keyboardModifiers.isCtrlPressed and pointerEvent.keyboardModifiers.isShiftPressed).
This way I fill a mutableStateListOf with all "selected" items.
I think the behavior is now like in my old Swing list (not easy to get all cases right with ctrl/shift 🤔!).
However, my items are wrapped in a ContextMenuArea to show a context menu for each item.
In Swing, right-clicking to open the context menu also selects an item (but only if it's not already selected, then ALL selected items remain selected).
My problem now is:
When the context menu opens, the PointerEvent.Press is fired so I can check if the clicked item needs to be selected.
However, if I right-click another item while the context menu is still open(!), then no PointerEvent.Press is fired?!
Any ideas how to get PointerEvents for right-clicking while the context menu is open?
By the way:
The documentation for the "onPointerEvent"-modifier says:
"_Note that this function is experimental, and can be replaced in the future by high-level functions"_
Is it known if there is a real plan to replace these features?MatthiasMeger
04/18/2023, 12:27 PMmodifier = Modifier
.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val pointerEvent = awaitPointerEvent()
val isMouseDown = pointerEvent.buttons.areAnyPressed
if(isMouseDown) {
println("click in pointer input modifier")
clicked(solution, pointerEvent)
}
}
}
}
.onPointerEvent(PointerEventType.Press) { println("click in onPointerEvent") }
The text "click in pointer input modifier" is also printed when I right-click while a contextMenu is displayed. However, the text "click in onPointerEvent" is not displayed, so that pointer event isn't fired when a contextMenu is open and then another item is clicked.
So the solution for me is to use the ".pointerInput(Unit)" modifier to check for clicks while the contextMenu is open.