Hello, is there a way to react on mouse scrolling ...
# compose-desktop
c
Hello, is there a way to react on mouse scrolling events? (like scroll up, scroll down with the mouse wheel)? Thank you very much ๐Ÿ™‚
o
are you interested in scroll events or mouse wheel events? did you check https://github.com/JetBrains/compose-jb/tree/master/tutorials/Desktop_Components#scrollbars?
c
In my case, it would be really just the event of the button itself, I wanted to make an image preview of a pdf page to be somehow "scrollable" by turning the mouse wheel (scroll between the pages, the event would replace the image).
o
See
Modifier.mouseScrollFilter
then
๐Ÿ‘€ 1
c
I will check, thanks already ๐Ÿ™‚
Thank you very much, it worked perfectly ๐Ÿ™‚
For anyone who is interested in my solution:
Copy code
@Composable
fun Modifier.onVerticalScroll(
    onScrollUp: () -> Unit = {},
    onScrollDown: () -> Unit = {}
) = mouseScrollFilter(
    onMouseScroll = { event, _ ->
        if (event.orientation == MouseScrollOrientation.Vertical) {
            when (val delta = event.delta) {
                is MouseScrollUnit.Line -> if (delta.value < 0) onScrollUp() else onScrollDown()
                is MouseScrollUnit.Page -> if (delta.value < 0) onScrollUp() else onScrollDown()
            }
        }
        false
    }
)
๐Ÿ‘๐Ÿผ 1
๐Ÿ‘๐Ÿป 1
๐Ÿ‘ 5