tornadofx
tornadofx copied to clipboard
MouseClick: Either onLeftClick {} or onRightClick {} prevents the other from working
`hbox { imageview { image = Image(ivAddContracteeUrl.toString()) fitHeight = 48.0 fitWidth = 48.0 isPickOnBounds = true
onLeftClick {
openInternalWindow(
view = ContracteeEditView(),
modal = true
)
}
onRightClick {
alert(Alert.AlertType.INFORMATION, "Info", "RightClick")
}
}
}`
Please tell me what I'm doing wrong or need to learn. Thanks in advance!
https://github.com/edvin/tornadofx/blob/7841a92eb491a8ec9e9f97a53d143e2995bc0d92/src/main/java/tornadofx/Nodes.kt#L420 these two different functions actually delegate the same function, which overrides the previous handler. Personally, it confuses me too.
Alternative:
val clickCount: Int = 1
setOnMouseClicked {
if (it.clickCount == clickCount && it.button === MouseButton.PRIMARY)
openInternalWindow(view = ContracteeEditView(), modal = true )
if (it.clickCount == clickCount && it.button === MouseButton.SECONDARY)
alert(Alert.AlertType.INFORMATION, "Info", "RightClick")
}
Thank you veeeery much for this working solution!
Shall we consider this as a bug?
Because, as you said It is very confusing. And the type hinting from the IDE should lead to expected results.
I made it a bit more kotlinish: val clicks = 1 setOnMouseClicked { mouseEvent -> mouseEvent.apply { if (clickCount == clicks && button === MouseButton.PRIMARY) openInternalWindow(view = ContracteeEditView(), modal = true )
if (clickCount == clicks && button === MouseButton.SECONDARY)
alert(Alert.AlertType.INFORMATION, "Info", "RightClick")
}
}
Shall we consider this as a bug?
No.
but I would fix that. I'll see when there is time