Hi, I would like to reproduce the example of the t...
# jewel
u
Hi, I would like to reproduce the example of the tabs, but I would like them to react to the scroll of the mouse, how to do this ?
s
They do scroll tho, don't they?
Let me check
u
They scroll if I grab the scrollbar and move it, but they don't react to mouse scrolling. Thanks a lot
s
Yeah, they do — if you scroll horizontally. The vertical scroll wheel does not scroll the tabs horizontally if that's what you're trying to do
u
yes that's what I'm trying to do 😕 I'm on a desktop PC, and the intellig tabs react to vertical mouse scrolling
s
u
ah great thank you very much
s
Tabs are a relatively uncommon component so it's not a highly prioritised job
fwiw, shift + vertical scroll does horizontal scroll in the meantime 🙃
👍 1
u
I will try to pr then 😅
👍 1
a workaround that isn't pretty but works 😬 :
Copy code
@OptIn(ExperimentalFoundationApi::class, ExperimentalComposeUiApi::class)
fun Modifier.verticalScrollToHorizontal(): Modifier = this.onPointerEvent(PointerEventType.Scroll) { event ->
    val change = event.changes.firstOrNull()
    if (change != null) {
        val scrollDelta = change.scrollDelta

        // If we detect vertical scroll (y != 0) and no horizontal scroll (x == 0)
        if (scrollDelta.y != 0f && scrollDelta.x == 0f) {
            try {
                // Use Robot to simulate Shift + Wheel
                val robot = Robot()

                // Press Shift
                robot.keyPress(KeyEvent.VK_SHIFT)

                // Wait a bit for the key to be properly registered
                Thread.sleep(10)

                // Simulate mouse scroll
                // Note: scrollDelta.y is negative for scroll up, positive for scroll down
                // MouseWheelEvent uses the inverse convention
                val scrollAmount = if (scrollDelta.y > 0) 1 else -1
                robot.mouseWheel(scrollAmount)

                // Release Shift
                Thread.sleep(10)
                robot.keyRelease(KeyEvent.VK_SHIFT)

                // Consume the original event to avoid double scroll
                change.consume()
            } catch (e: Exception) {
                // In case of error (for example on certain platforms where Robot is not available)
                e.printStackTrace()
            }
        }
    }
}
s
Yeah, it's likely we'll end up with something like this too
Or just capture the vertical scroll deltas and add them to the horizontal scroll state
which seems less hacky
👍 1
u
but as a user of the library I do not have access to the scroll state
but yes as a pr in the library, it's less hacky
s
We should also expose the scroll state at some point 😄
😅 1