Skip to content

Commit

Permalink
Scroller fix: don't respond to mouse scroll if direction is ScrollNone
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed May 23, 2024
1 parent a287ba6 commit 863340e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/fyne_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ func makeNav(setTutorial func(tutorial tutorials.Tutorial), loadPrevious bool) f

themes := container.NewGridWithColumns(2,
widget.NewButton("Dark", func() {
a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantDark})
//a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantDark})
}),
widget.NewButton("Light", func() {
a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantLight})
//a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantLight})
}),
)

Expand Down
4 changes: 3 additions & 1 deletion internal/widget/scroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ func (s *Scroll) refreshWithoutOffsetUpdate() {

// Scrolled is called when an input device triggers a scroll event
func (s *Scroll) Scrolled(ev *fyne.ScrollEvent) {
s.scrollBy(ev.Scrolled.DX, ev.Scrolled.DY)
if s.Direction != ScrollNone {
s.scrollBy(ev.Scrolled.DX, ev.Scrolled.DY)
}
}

func (s *Scroll) scrollBy(dx, dy float32) {
Expand Down
13 changes: 13 additions & 0 deletions internal/widget/scroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ func TestScrollContainer_Scrolled_Back(t *testing.T) {
assert.Equal(t, float32(0), scroll.Offset.Y)
}

func TestScrollContainer_Scrolled_ScrollNone(t *testing.T) {
rect := canvas.NewRectangle(color.Black)
rect.SetMinSize(fyne.NewSize(1000, 1000))
scroll := NewScroll(rect)
scroll.Direction = ScrollNone
scroll.Resize(fyne.NewSize(100, 100))
assert.Equal(t, float32(0), scroll.Offset.X)
assert.Equal(t, float32(0), scroll.Offset.Y)
scroll.Scrolled(&fyne.ScrollEvent{Scrolled: fyne.NewDelta(-10, -10)})
assert.Equal(t, float32(0), scroll.Offset.X)
assert.Equal(t, float32(0), scroll.Offset.Y)
}

func TestScrollContainer_Scrolled_BackLimit(t *testing.T) {
rect := canvas.NewRectangle(color.Black)
scroll := NewScroll(rect)
Expand Down

0 comments on commit 863340e

Please sign in to comment.