Skip to content

Commit

Permalink
Fix tapping of a check when its height > minHeight
Browse files Browse the repository at this point in the history
Fixes #5331
  • Loading branch information
andydotxyz committed Dec 18, 2024
1 parent 7fea2eb commit 9b66d57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion widget/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ func (c *Check) Tapped(pe *fyne.PointEvent) {
if c.Disabled() {
return
}

minHeight := c.minSize.Height
minY := (c.Size().Height - minHeight) / 2
if !c.minSize.IsZero() &&
(pe.Position.X > c.minSize.Width || pe.Position.Y > c.minSize.Height) {
(pe.Position.X > c.minSize.Width || pe.Position.Y < minY || pe.Position.Y > minY+minHeight) {
// tapped outside the active area of the widget
return
}
Expand Down
14 changes: 14 additions & 0 deletions widget/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,19 @@ func TestCheck_Tapped(t *testing.T) {
test.Tap(check)
assert.False(t, check.Checked)
assert.False(t, check.Partial)
}

func TestCheck_Resize(t *testing.T) {
check := &widget.Check{Text: "test"}
check.Resize(fyne.NewSize(300, 200))
min := check.MinSize() // set up min cache
assert.Less(t, min.Height, check.Size().Height)

test.TapAt(check, fyne.NewPos(10, 100))
assert.True(t, check.Checked)
test.TapAt(check, fyne.NewPos(10, 100))
assert.False(t, check.Checked)

test.TapAt(check, fyne.NewPos(10, 10))
assert.False(t, check.Checked)
}

0 comments on commit 9b66d57

Please sign in to comment.