diff --git a/internal/widget/scroller.go b/internal/widget/scroller.go index 7360e30861..06e955ffd0 100644 --- a/internal/widget/scroller.go +++ b/internal/widget/scroller.go @@ -87,6 +87,7 @@ func (b *scrollBar) DragEnd() { if fyne.CurrentDevice().IsMobile() { b.area.MouseOut() } + b.area.Refresh() } func (b *scrollBar) Dragged(e *fyne.DragEvent) { @@ -129,6 +130,10 @@ func newScrollBar(area *scrollBarArea) *scrollBar { return b } +func (r *scrollBarArea) isLarge() bool { + return r.isMouseIn || r.isDragged +} + type scrollBarAreaRenderer struct { BaseRenderer area *scrollBarArea @@ -149,7 +154,7 @@ func (r *scrollBarAreaRenderer) Layout(_ fyne.Size) { func (r *scrollBarAreaRenderer) MinSize() fyne.Size { min := theme.ScrollBarSize() - if !r.area.isLarge { + if !r.area.isLarge() { min = theme.ScrollBarSmallSize() * 2 } switch r.area.orientation { @@ -177,7 +182,7 @@ func (r *scrollBarAreaRenderer) barSizeAndOffset(contentOffset, contentLength, s if contentOffset != 0 { lengthOffset = (scrollLength - length) * (contentOffset / (contentLength - scrollLength)) } - if r.area.isLarge { + if r.area.isLarge() { width = scrollBarSize } else { widthOffset = theme.ScrollBarSmallSize() @@ -192,7 +197,7 @@ type scrollBarArea struct { Base isDragged bool - isLarge bool + isMouseIn bool scroll *Scroll orientation scrollBarOrientation } @@ -203,7 +208,7 @@ func (a *scrollBarArea) CreateRenderer() fyne.WidgetRenderer { } func (a *scrollBarArea) MouseIn(*desktop.MouseEvent) { - a.isLarge = true + a.isMouseIn = true a.scroll.Refresh() } @@ -211,11 +216,11 @@ func (a *scrollBarArea) MouseMoved(*desktop.MouseEvent) { } func (a *scrollBarArea) MouseOut() { + a.isMouseIn = false if a.isDragged { return } - a.isLarge = false a.scroll.Refresh() } diff --git a/internal/widget/scroller_test.go b/internal/widget/scroller_test.go index 823642a336..10eeb9908b 100644 --- a/internal/widget/scroller_test.go +++ b/internal/widget/scroller_test.go @@ -791,19 +791,19 @@ func TestScrollBar_LargeHandleWhileInDrag(t *testing.T) { // Make sure that hovering makes the bar large. mouseEvent := &desktop.MouseEvent{} - assert.False(t, scrollBarHoriz.area.isLarge) + assert.False(t, scrollBarHoriz.area.isLarge()) scrollBarHoriz.MouseIn(mouseEvent) - assert.True(t, scrollBarHoriz.area.isLarge) + assert.True(t, scrollBarHoriz.area.isLarge()) scrollBarHoriz.MouseOut() - assert.False(t, scrollBarHoriz.area.isLarge) + assert.False(t, scrollBarHoriz.area.isLarge()) // Make sure that the bar stays large when dragging, even if the mouse leaves the bar. dragEvent := &fyne.DragEvent{Dragged: fyne.Delta{DX: 10}} scrollBarHoriz.Dragged(dragEvent) - assert.True(t, scrollBarHoriz.area.isLarge) + assert.True(t, scrollBarHoriz.area.isLarge()) scrollBarHoriz.MouseOut() - assert.True(t, scrollBarHoriz.area.isLarge) + assert.True(t, scrollBarHoriz.area.isLarge()) scrollBarHoriz.DragEnd() scrollBarHoriz.MouseOut() - assert.False(t, scrollBarHoriz.area.isLarge) + assert.False(t, scrollBarHoriz.area.isLarge()) }