Skip to content

Commit 6e239f5

Browse files
authored
Merge pull request #10 from ErikKalkoken/feat-improve-readme-2
feat: further improve readme
2 parents b483cf4 + 036f229 commit 6e239f5

1 file changed

Lines changed: 81 additions & 36 deletions

File tree

README.md

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,71 @@
11
# fyne-tooltip
22

3+
Add-on package for Fyne adding tooltip support.
34

5+
[![GitHub Release](https://img.shields.io/github/v/release/dweymouth/fyne-tooltip)](https://github.com/dweymouth/fyne-tooltip/releases)
6+
[![Fyne](https://img.shields.io/badge/dynamic/regex?url=https%3A%2F%2Fgithub.com%2Fdweymouth%2Ffyne-tooltip%2Fblob%2Fmain%2Fgo.mod&search=fyne%5C.io%5C%2Ffyne%5C%2Fv2%20(v%5Cd*%5C.%5Cd*%5C.%5Cd*)&replace=%241&label=Fyne&cacheSeconds=https%3A%2F%2Fgithub.com%2Ffyne-io%2Ffyne)](https://github.com/fyne-io/fyne)
7+
[![Go Reference](https://pkg.go.dev/badge/github.com/dweymouth/fyne-tooltip.svg)](https://pkg.go.dev/github.com/dweymouth/fyne-tooltip)
8+
[![GitHub License](https://img.shields.io/github/license/dweymouth/fyne-tooltip)](https://github.com/dweymouth/fyne-tooltip?tab=MIT-1-ov-file#readme)
49

5-
https://github.com/user-attachments/assets/e9a2b9dd-9d6c-49f2-9c3a-b896fec4609d
10+
## Contents
11+
12+
- [Overview](#overview)
13+
- [Demo](#demo)
14+
- [Example](#example)
15+
- [Guide](#guide)
16+
- [Enabling tool tips in a window](#enabling-tool-tips-in-a-window)
17+
- [Using built-in tool tip widgets](#using-built-in-tool-tip-widgets)
18+
- [Enabling tool tips in a PopUp](#enabling-tool-tips-in-a-popup)
19+
- [Creating new tool tip widgets](#creating-new-tool-tip-widgets)
20+
- [Extending existing widgets for tool tip support](#extending-existing-widgets-for-tool-tip-support)
621

22+
## Overview
723

824
**fyne-tooltip** is an add-on package for Fyne adding tooltip support. It provides a tool tip rendering system, along with drop-in tooltip-enabled extensions of several of the Fyne builtin widgets, as well as an easy means to extend existing widgets to add tool tip support, or creating new tooltip-enabled custom widgets. It aims to be easy and low-friction to integrate into your existing Fyne projects, as well as easy to remove and switch back to Fyne core if and when tooltips are supported natively.
925

1026
Tool tip widgets implement `desktop.Hoverable` to show the tool tips after a short delay on MouseIn, and hide them on MouseOut.
1127

12-
## Enabling tool tips in a window
28+
## Demo
29+
30+
In the following video you can see how tooltips look with **fyne-tooltip** in a Fyne app. The source code is available at `cmd/example.go`.
31+
32+
https://github.com/user-attachments/assets/e9a2b9dd-9d6c-49f2-9c3a-b896fec4609d
33+
34+
## Example
35+
36+
The following is a complete Fyne app that shows how to use **fyne-tooltip** with a label widget.
37+
38+
```go
39+
package main
40+
41+
import (
42+
"fyne.io/fyne/v2"
43+
"fyne.io/fyne/v2/app"
44+
"fyne.io/fyne/v2/container"
45+
fynetooltip "github.com/dweymouth/fyne-tooltip"
46+
ttwidget "github.com/dweymouth/fyne-tooltip/widget"
47+
)
48+
49+
func main() {
50+
myApp := app.New()
51+
myWindow := myApp.NewWindow("Example")
52+
53+
label := ttwidget.NewLabel("This is a label")
54+
label.SetToolTip("This is a tooltip")
55+
56+
content := container.NewCenter(label)
57+
myWindow.SetContent(fynetooltip.AddWindowToolTipLayer(content, myWindow.Canvas()))
58+
59+
myWindow.Resize(fyne.NewSize(800, 600))
60+
myWindow.ShowAndRun()
61+
}
62+
```
63+
64+
## Guide
65+
66+
This chapter explains how **fyne-tooltip** works and how to use it in your own Fyne apps.
67+
68+
### Enabling tool tips in a window
1369

1470
**fyne-tooltip** requires tool tip layers to be created for the tool tips to be rendered into, and provides APIs to do so for windows and pop-ups. It is called when setting the window's content:
1571

@@ -27,7 +83,7 @@ window.SetCloseIntercept(func() {
2783
})
2884
```
2985

30-
## Using built-in tool tip widgets
86+
### Using built-in tool tip widgets
3187

3288
Drop-in replacements for several built-in Fyne widgets are provided, which have been extended from the base implementation to add tool tip support.
3389

@@ -46,7 +102,7 @@ func main() {
46102
}
47103
```
48104

49-
## Enabling tool tips in a PopUp
105+
### Enabling tool tips in a PopUp
50106

51107
Similarly to windows, **fyne-tooltip** requires a tool tip layer to be created for pop ups to enable tool tips to be shown.
52108
It is called after creating the pop up with content, but before showing it.
@@ -60,7 +116,7 @@ pop.Show()
60116
The pop up may be hidden and re-shown. It is only necessary to create the pop up layer once. When the popup is hidden and will not be shown again,
61117
it is important to call `DestroyPopUpToolTipLayer` to release memory resources associated with the tool tip layer.
62118

63-
## Creating new tool tip widgets
119+
### Creating new tool tip widgets
64120

65121
To create custom widgets that are tool tip enabled, just extend from the `ToolTipWidget` base struct instead of `BaseWidget`. The widget will automatically
66122
have a SetToolTip API, and the mouse event hooks added to show and hide the tool tip.
@@ -79,7 +135,26 @@ func NewMyWidget() *MyWidget {
79135
}
80136
```
81137

82-
## Extending existing widgets for tool tip support
138+
If your custom widget implements `desktop.Hoverable`, e.g. to make it tappable, you must also forward calls to `ToolTipWidget` in your overridden methods to enable tooltips to work. Here is an example for how this could be implemented:
139+
140+
```go
141+
func (w *CustomWidget) MouseIn(e *desktop.MouseEvent) {
142+
w.ToolTipWidgetExtend.MouseIn(e)
143+
// custom logic
144+
}
145+
146+
func (w *CustomWidget) MouseMoved(e *desktop.MouseEvent) {
147+
w.ToolTipWidgetExtend.MouseMoved(e)
148+
// custom logic
149+
}
150+
151+
func (w *CustomWidget) MouseOut() {
152+
w.ToolTipWidgetExtend.MouseOut()
153+
// custom logic
154+
}
155+
```
156+
157+
### Extending existing widgets for tool tip support
83158

84159
To extend existing widgets with tool tip support, use the `ToolTipWidgetExtend` struct. You must override `ExtendBaseWidget` to call both the
85160
parent widget's `ExtendBaseWidget`, as well as `ExtendToolTipWidget`
@@ -130,33 +205,3 @@ func (b *Button) MouseMoved(e *desktop.MouseEvent) {
130205
b.Button.MouseMoved(e)
131206
}
132207
```
133-
134-
## Example app
135-
136-
Below is a complete example app that shows how to use **fyne-tooltips**. The source code of the example app shown in the video is also available at `cmd/example.go`.
137-
138-
```go
139-
package main
140-
141-
import (
142-
"fyne.io/fyne/v2"
143-
"fyne.io/fyne/v2/app"
144-
"fyne.io/fyne/v2/container"
145-
fynetooltip "github.com/dweymouth/fyne-tooltip"
146-
ttwidget "github.com/dweymouth/fyne-tooltip/widget"
147-
)
148-
149-
func main() {
150-
myApp := app.New()
151-
myWindow := myApp.NewWindow("Example")
152-
153-
label := ttwidget.NewLabel("This is a label")
154-
label.SetToolTip("This is a tooltip")
155-
156-
content := container.NewCenter(label)
157-
myWindow.SetContent(fynetooltip.AddWindowToolTipLayer(content, myWindow.Canvas()))
158-
159-
myWindow.Resize(fyne.NewSize(800, 600))
160-
myWindow.ShowAndRun()
161-
}
162-
```

0 commit comments

Comments
 (0)