~whereswaldon/gio-x

56e1072e2fcf0b5ed7773c0e5953763f8b2c39ea — Chris Waldon a month ago 73f03ea
component: add tooltip iconbutton wrapper

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
3 files changed, 21 insertions(+), 2 deletions(-)

M component/tooltip.go
M component/tooltip_desktop.go
M component/tooltip_mobile.go
M component/tooltip.go => component/tooltip.go +19 -0
@@ 13,6 13,7 @@ import (
	"gioui.org/op/clip"
	"gioui.org/op/paint"
	"gioui.org/unit"
	"gioui.org/widget"
	"gioui.org/widget/material"
)



@@ 188,3 189,21 @@ func (t *TipArea) Layout(gtx C, tip Tooltip, w layout.Widget) D {
		}),
	)
}

type TipIconButtonStyle struct {
	Tooltip
	material.IconButtonStyle
	State *TipArea
}

func TipIconButton(th *material.Theme, area *TipArea, button *widget.Clickable, label string, icon *widget.Icon) TipIconButtonStyle {
	return TipIconButtonStyle{
		IconButtonStyle: material.IconButton(th, button, icon),
		State:           area,
		Tooltip:         PlatformTooltip(th, label),
	}
}

func (t TipIconButtonStyle) Layout(gtx C) D {
	return t.State.Layout(gtx, t.Tooltip, t.IconButtonStyle.Layout)
}

M component/tooltip_desktop.go => component/tooltip_desktop.go +1 -1
@@ 8,5 8,5 @@ import "gioui.org/widget/material"
// (desktop or mobile) by choosing based on the OS. This choice may
// not always be appropriate as it only uses the OS to decide.
func PlatformTooltip(th *material.Theme, text string) Tooltip {
    return DesktopTooltip(th, text)
	return DesktopTooltip(th, text)
}

M component/tooltip_mobile.go => component/tooltip_mobile.go +1 -1
@@ 8,5 8,5 @@ import "gioui.org/widget/material"
// (desktop or mobile) by choosing based on the OS. This choice may
// not always be appropriate as it only uses the OS to decide.
func PlatformTooltip(th *material.Theme, text string) Tooltip {
    return MobileTooltip(th, text)
	return MobileTooltip(th, text)
}