Skip to content

Commit

Permalink
add API for Label and RichText to propagate received hover events
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Aug 4, 2024
1 parent 12f4f05 commit f7de9ff
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions widget/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ package widget
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/widget"
)

// Label widget is a label component with appropriate padding and layout.
//
// NOTE: since the tool tip label implements desktop.Hoverable while the
// standard Label does not, this widget may result in hover events not
// reaching the parent Hoverable widget. It provides a callback API to allow
// parent widgets to be notified of hover events received on this widget.
type Label struct {
widget.Label
ToolTipWidgetExtend

// Sets a callback that will be invoked for MouseIn events received
OnMouseIn func(*desktop.MouseEvent)
// Sets a callback that will be invoked for MouseMoved events received
OnMouseMoved func(*desktop.MouseEvent)
// Sets a callback that will be invoked for MouseOut events received
OnMouseOut func()
}

// NewLabel creates a new label widget with the set text content
Expand Down Expand Up @@ -43,3 +56,24 @@ func (l *Label) ExtendBaseWidget(wid fyne.Widget) {
l.ExtendToolTipWidget(wid)
l.Label.ExtendBaseWidget(wid)
}

func (l *Label) MouseIn(e *desktop.MouseEvent) {
l.ToolTipWidgetExtend.MouseIn(e)
if f := l.OnMouseIn; f != nil {
f(e)
}
}

func (l *Label) MouseMoved(e *desktop.MouseEvent) {
l.ToolTipWidgetExtend.MouseMoved(e)
if f := l.OnMouseMoved; f != nil {
f(e)
}
}

func (l *Label) MouseOut() {
l.ToolTipWidgetExtend.MouseOut()
if f := l.OnMouseOut; f != nil {
f()
}
}
34 changes: 34 additions & 0 deletions widget/richtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ package widget
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/widget"
)

// RichText represents the base element for a rich text-based widget.
//
// NOTE: since the tool tip RichText implements desktop.Hoverable while the
// standard RichText does not, this widget may result in hover events not
// reaching the parent Hoverable widget. It provides a callback API to allow
// parent widgets to be notified of hover events received on this widget.
type RichText struct {
widget.RichText
ToolTipWidgetExtend

// Sets a callback that will be invoked for MouseIn events received
OnMouseIn func(*desktop.MouseEvent)
// Sets a callback that will be invoked for MouseMoved events received
OnMouseMoved func(*desktop.MouseEvent)
// Sets a callback that will be invoked for MouseOut events received
OnMouseOut func()
}

// NewRichText returns a new RichText widget that renders the given text and segments.
Expand All @@ -34,3 +47,24 @@ func (r *RichText) ExtendBaseWidget(wid fyne.Widget) {
r.ExtendToolTipWidget(wid)
r.RichText.ExtendBaseWidget(wid)
}

func (r *RichText) MouseIn(e *desktop.MouseEvent) {
r.ToolTipWidgetExtend.MouseIn(e)
if f := r.OnMouseIn; f != nil {
f(e)
}
}

func (r *RichText) MouseMoved(e *desktop.MouseEvent) {
r.ToolTipWidgetExtend.MouseMoved(e)
if f := r.OnMouseMoved; f != nil {
f(e)
}
}

func (r *RichText) MouseOut() {
r.ToolTipWidgetExtend.MouseOut()
if f := r.OnMouseOut; f != nil {
f()
}
}

0 comments on commit f7de9ff

Please sign in to comment.