Skip to content

Commit 036f229

Browse files
committed
feat: Add badges to README and improve structure
1 parent d41572e commit 036f229

1 file changed

Lines changed: 61 additions & 44 deletions

File tree

README.md

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +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
611

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)
21+
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-
## Contents
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
1365

14-
- [Enabling tool tips in a window](#enabling-tool-tips-in-a-window)
15-
- [Using built-in tool tip widgets](#using-built-in-tool-tip-widgets)
16-
- [Enabling tool tips in a PopUp](#enabling-tool-tips-in-a-popup)
17-
- [Creating new tool tip widgets](#creating-new-tool-tip-widgets)
18-
- [Extending existing widgets for tool tip support](#extending-existing-widgets-for-tool-tip-support)
19-
- [Example app](#example-app)
66+
This chapter explains how **fyne-tooltip** works and how to use it in your own Fyne apps.
2067

21-
## Enabling tool tips in a window
68+
### Enabling tool tips in a window
2269

2370
**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:
2471

@@ -36,7 +83,7 @@ window.SetCloseIntercept(func() {
3683
})
3784
```
3885

39-
## Using built-in tool tip widgets
86+
### Using built-in tool tip widgets
4087

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

@@ -55,7 +102,7 @@ func main() {
55102
}
56103
```
57104

58-
## Enabling tool tips in a PopUp
105+
### Enabling tool tips in a PopUp
59106

60107
Similarly to windows, **fyne-tooltip** requires a tool tip layer to be created for pop ups to enable tool tips to be shown.
61108
It is called after creating the pop up with content, but before showing it.
@@ -69,7 +116,7 @@ pop.Show()
69116
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,
70117
it is important to call `DestroyPopUpToolTipLayer` to release memory resources associated with the tool tip layer.
71118

72-
## Creating new tool tip widgets
119+
### Creating new tool tip widgets
73120

74121
To create custom widgets that are tool tip enabled, just extend from the `ToolTipWidget` base struct instead of `BaseWidget`. The widget will automatically
75122
have a SetToolTip API, and the mouse event hooks added to show and hide the tool tip.
@@ -88,7 +135,7 @@ func NewMyWidget() *MyWidget {
88135
}
89136
```
90137

91-
If your custom widget implements `desktop.Hoverable`, e.g. to make it tappable, you must also forward calls to `ToolTipWidget` in your overriden methods to enable tooltips to work. Here is an example for how this could be implemented:
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:
92139

93140
```go
94141
func (w *CustomWidget) MouseIn(e *desktop.MouseEvent) {
@@ -107,7 +154,7 @@ func (w *CustomWidget) MouseOut() {
107154
}
108155
```
109156

110-
## Extending existing widgets for tool tip support
157+
### Extending existing widgets for tool tip support
111158

112159
To extend existing widgets with tool tip support, use the `ToolTipWidgetExtend` struct. You must override `ExtendBaseWidget` to call both the
113160
parent widget's `ExtendBaseWidget`, as well as `ExtendToolTipWidget`
@@ -158,33 +205,3 @@ func (b *Button) MouseMoved(e *desktop.MouseEvent) {
158205
b.Button.MouseMoved(e)
159206
}
160207
```
161-
162-
## Example app
163-
164-
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`.
165-
166-
```go
167-
package main
168-
169-
import (
170-
"fyne.io/fyne/v2"
171-
"fyne.io/fyne/v2/app"
172-
"fyne.io/fyne/v2/container"
173-
fynetooltip "github.com/dweymouth/fyne-tooltip"
174-
ttwidget "github.com/dweymouth/fyne-tooltip/widget"
175-
)
176-
177-
func main() {
178-
myApp := app.New()
179-
myWindow := myApp.NewWindow("Example")
180-
181-
label := ttwidget.NewLabel("This is a label")
182-
label.SetToolTip("This is a tooltip")
183-
184-
content := container.NewCenter(label)
185-
myWindow.SetContent(fynetooltip.AddWindowToolTipLayer(content, myWindow.Canvas()))
186-
187-
myWindow.Resize(fyne.NewSize(800, 600))
188-
myWindow.ShowAndRun()
189-
}
190-
```

0 commit comments

Comments
 (0)