-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtooltip.go
52 lines (48 loc) · 1.27 KB
/
tooltip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ux
import (
"gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"gioui.org/x/component"
)
type (
TipIconButton struct {
*widget.Clickable
material.IconButtonStyle
component.Tooltip
component.TipArea
callback func()
}
)
func NewTooltipButton(icon *widget.Icon, tip string, callback func()) *TipIconButton {
t := component.PlatformTooltip(th.Theme, tip)
t.Bg = Yellow100
t.Text.Color = th.Color.ButtonTextBlackColor
t.CornerRadius = 14
t.Text.MaxLines = 3 // todo newlines
clickable := &widget.Clickable{}
iconButtonStyle := material.IconButton(th.Theme, clickable, icon, "")
iconButtonStyle.Color = th.Fg
iconButtonStyle.Background = th.Color.InputFocusedBgColor
iconButtonStyle.Inset = layout.UniformInset(unit.Dp(6))
b := &TipIconButton{
Clickable: clickable,
IconButtonStyle: iconButtonStyle,
Tooltip: t,
TipArea: component.TipArea{},
callback: callback,
}
return b
}
func (t *TipIconButton) Layout(gtx C) D {
if t.Clickable.Clicked(gtx) {
if t.callback != nil {
t.callback()
}
}
// return t.TipArea.Layout(gtx, t.Tooltip, t.IconButtonStyle.Layout)
return layout.Inset{Top: 4}.Layout(gtx, func(gtx C) D {
return t.TipArea.Layout(gtx, t.Tooltip, t.IconButtonStyle.Layout)
})
}