From 9e8e986977bcd9eb0f5f4b6f0924fc7e48a64684 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 11 Feb 2023 22:17:03 -0500 Subject: [PATCH] Changes to how scroll bars respond to the mouse - Left clicking on the gutter jumps to that position - Right clicking on the gutter scrolls incrementally towards that position - Middle clicking on the gutter pages up or down to that position --- elements/basic/scrollcontainer.go | 50 ++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/elements/basic/scrollcontainer.go b/elements/basic/scrollcontainer.go index 8d3e539..5b3060e 100644 --- a/elements/basic/scrollcontainer.go +++ b/elements/basic/scrollcontainer.go @@ -158,12 +158,26 @@ func (element *ScrollContainer) HandleMouseDown (x, y int, button input.Button) element.dragHorizontalBar(point) } else if point.In(element.horizontal.gutter) { - // FIXME: x backend and scroll container should pull these - // values from the same place - if x > element.horizontal.bar.Min.X { - element.scrollChildBy(velocity, 0) - } else { - element.scrollChildBy(-velocity, 0) + switch button { + case input.ButtonLeft: + element.horizontal.dragging = true + element.horizontal.dragOffset = + element.horizontal.bar.Dx() / 2 + + element.Bounds().Min.X + element.dragHorizontalBar(point) + case input.ButtonMiddle: + viewport := element.child.ScrollViewportBounds().Dx() + if x > element.horizontal.bar.Min.X { + element.scrollChildBy(viewport, 0) + } else { + element.scrollChildBy(-viewport, 0) + } + case input.ButtonRight: + if x > element.horizontal.bar.Min.X { + element.scrollChildBy(velocity, 0) + } else { + element.scrollChildBy(-velocity, 0) + } } } else if point.In(element.vertical.bar) { @@ -174,10 +188,26 @@ func (element *ScrollContainer) HandleMouseDown (x, y int, button input.Button) element.dragVerticalBar(point) } else if point.In(element.vertical.gutter) { - if y > element.vertical.bar.Min.Y { - element.scrollChildBy(0, velocity) - } else { - element.scrollChildBy(0, -velocity) + switch button { + case input.ButtonLeft: + element.vertical.dragging = true + element.vertical.dragOffset = + element.vertical.bar.Dy() / 2 + + element.Bounds().Min.Y + element.dragVerticalBar(point) + case input.ButtonMiddle: + viewport := element.child.ScrollViewportBounds().Dy() + if y > element.vertical.bar.Min.Y { + element.scrollChildBy(0, viewport) + } else { + element.scrollChildBy(0, -viewport) + } + case input.ButtonRight: + if y > element.vertical.bar.Min.Y { + element.scrollChildBy(0, velocity) + } else { + element.scrollChildBy(0, -velocity) + } } } else if child, ok := element.child.(elements.MouseTarget); ok {