Scrollbars respond to mouse dragging more naturally
This commit is contained in:
parent
d435f5a6a9
commit
92a9c9370d
@ -272,10 +272,7 @@ func (window *Window) compressMotionNotify (
|
|||||||
typedEvent, ok := untypedEvent.Event.(xproto.MotionNotifyEvent)
|
typedEvent, ok := untypedEvent.Event.(xproto.MotionNotifyEvent)
|
||||||
if !ok { continue }
|
if !ok { continue }
|
||||||
|
|
||||||
if firstEvent.Event == typedEvent.Event &&
|
if firstEvent.Event == typedEvent.Event {
|
||||||
typedEvent.Detail >= 4 &&
|
|
||||||
typedEvent.Detail <= 7 {
|
|
||||||
|
|
||||||
lastEvent = typedEvent
|
lastEvent = typedEvent
|
||||||
defer func (index int) {
|
defer func (index int) {
|
||||||
xevent.DequeueAt(window.backend.connection, index)
|
xevent.DequeueAt(window.backend.connection, index)
|
||||||
|
@ -20,7 +20,7 @@ type ScrollContainer struct {
|
|||||||
exists bool
|
exists bool
|
||||||
enabled bool
|
enabled bool
|
||||||
dragging bool
|
dragging bool
|
||||||
dragOffset image.Point
|
dragOffset int
|
||||||
gutter image.Rectangle
|
gutter image.Rectangle
|
||||||
bar image.Rectangle
|
bar image.Rectangle
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ type ScrollContainer struct {
|
|||||||
exists bool
|
exists bool
|
||||||
enabled bool
|
enabled bool
|
||||||
dragging bool
|
dragging bool
|
||||||
dragOffset image.Point
|
dragOffset int
|
||||||
gutter image.Rectangle
|
gutter image.Rectangle
|
||||||
bar image.Rectangle
|
bar image.Rectangle
|
||||||
}
|
}
|
||||||
@ -111,12 +111,16 @@ func (element *ScrollContainer) HandleKeyUp (key tomo.Key, modifiers tomo.Modifi
|
|||||||
|
|
||||||
func (element *ScrollContainer) HandleMouseDown (x, y int, button tomo.Button) {
|
func (element *ScrollContainer) HandleMouseDown (x, y int, button tomo.Button) {
|
||||||
point := image.Pt(x, y)
|
point := image.Pt(x, y)
|
||||||
if point.In(element.horizontal.gutter) {
|
if point.In(element.horizontal.bar) {
|
||||||
element.horizontal.dragging = true
|
element.horizontal.dragging = true
|
||||||
|
element.horizontal.dragOffset =
|
||||||
|
point.Sub(element.horizontal.bar.Min).X
|
||||||
element.dragHorizontalBar(point)
|
element.dragHorizontalBar(point)
|
||||||
|
|
||||||
} else if point.In(element.vertical.gutter) {
|
} else if point.In(element.vertical.bar) {
|
||||||
element.vertical.dragging = true
|
element.vertical.dragging = true
|
||||||
|
element.vertical.dragOffset =
|
||||||
|
point.Sub(element.vertical.bar.Min).Y
|
||||||
element.dragVerticalBar(point)
|
element.dragVerticalBar(point)
|
||||||
|
|
||||||
} else if child, ok := element.child.(tomo.MouseTarget); ok {
|
} else if child, ok := element.child.(tomo.MouseTarget); ok {
|
||||||
@ -353,8 +357,7 @@ func (element *ScrollContainer) dragHorizontalBar (mousePosition image.Point) {
|
|||||||
scrollX :=
|
scrollX :=
|
||||||
float64(element.child.ScrollContentBounds().Dx()) /
|
float64(element.child.ScrollContentBounds().Dx()) /
|
||||||
float64(element.horizontal.gutter.Dx()) *
|
float64(element.horizontal.gutter.Dx()) *
|
||||||
float64 (
|
float64(mousePosition.X - element.horizontal.dragOffset)
|
||||||
mousePosition.X - element.horizontal.bar.Dx() / 2)
|
|
||||||
scrollY := element.child.ScrollViewportBounds().Min.Y
|
scrollY := element.child.ScrollViewportBounds().Min.Y
|
||||||
element.child.ScrollTo(image.Pt(int(scrollX), scrollY))
|
element.child.ScrollTo(image.Pt(int(scrollX), scrollY))
|
||||||
}
|
}
|
||||||
@ -363,8 +366,7 @@ func (element *ScrollContainer) dragVerticalBar (mousePosition image.Point) {
|
|||||||
scrollY :=
|
scrollY :=
|
||||||
float64(element.child.ScrollContentBounds().Dy()) /
|
float64(element.child.ScrollContentBounds().Dy()) /
|
||||||
float64(element.vertical.gutter.Dy()) *
|
float64(element.vertical.gutter.Dy()) *
|
||||||
float64 (
|
float64(mousePosition.Y - element.vertical.dragOffset)
|
||||||
mousePosition.Y - element.vertical.bar.Dy() / 2)
|
|
||||||
scrollX := element.child.ScrollViewportBounds().Min.X
|
scrollX := element.child.ScrollViewportBounds().Min.X
|
||||||
element.child.ScrollTo(image.Pt(scrollX, int(scrollY)))
|
element.child.ScrollTo(image.Pt(scrollX, int(scrollY)))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user