Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Oct 16, 2023
1 parent 4e56632 commit 2d520b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions widget/hyperlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ func (hl *Hyperlink) MouseOut() {
func (hl *Hyperlink) isPosOverText(pos fyne.Position) bool {
innerPad := theme.InnerPadding()
pad := theme.Padding()
lineCount := float32(len(hl.provider.rowBounds))
// If not rendered yet provider will be nil
lineCount := float32(1)
if hl.provider != nil {
lineCount = fyne.Max(lineCount, float32(len(hl.provider.rowBounds)))
}
return pos.X >= innerPad/2 && pos.X <= hl.textSize.Width+pad*2+innerPad/2 &&
pos.Y >= innerPad/2 && pos.Y <= hl.textSize.Height*lineCount+pad*2+innerPad/2
}
Expand Down Expand Up @@ -174,7 +178,9 @@ func (hl *Hyperlink) SetURLFromString(str string) error {

// Tapped is called when a pointer tapped event is captured and triggers any change handler
func (hl *Hyperlink) Tapped(e *fyne.PointEvent) {
if !hl.isPosOverText(e.Position) {
// If not rendered yet (hl.provider == nil), register all taps
// in practice this probably only happens in our unit tests
if hl.provider != nil && !hl.isPosOverText(e.Position) {
return
}
hl.invokeAction()
Expand Down
3 changes: 3 additions & 0 deletions widget/hyperlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func TestHyperlink_Cursor(t *testing.T) {
hyperlink := NewHyperlink("Test", u)

assert.Nil(t, err)
assert.Equal(t, desktop.DefaultCursor, hyperlink.Cursor())

hyperlink.hovered = true
assert.Equal(t, desktop.PointerCursor, hyperlink.Cursor())
}

Expand Down

0 comments on commit 2d520b7

Please sign in to comment.