1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-16 19:22:51 +00:00
cchat-gtk/internal/ui/rich/image.go

36 lines
714 B
Go
Raw Normal View History

2020-06-06 07:44:36 +00:00
package rich
import "log"
2020-08-17 00:13:47 +00:00
// ImageURLSetter describes an image that can be set a URL.
type ImageURLSetter interface {
SetImageURL(url string)
2020-08-17 00:13:47 +00:00
}
type tooltipSetter interface {
SetTooltipText(text string)
2020-06-06 07:44:36 +00:00
}
// BindRoundImage binds a round image to a rich label state store.
func BindRoundImage(img ImageURLSetter, state LabelStateStorer, tooltip bool) {
var setTooltip func(string)
2020-06-06 07:44:36 +00:00
if tooltip {
tooltipper, ok := img.(tooltipSetter)
if !ok {
log.Panicf("img of type %T is not tooltipSetter", img)
}
2020-06-06 07:44:36 +00:00
setTooltip = tooltipper.SetTooltipText
2020-12-20 08:18:23 +00:00
}
state.OnUpdate(func() {
image := state.Image()
img.SetImageURL(image.URL)
if setTooltip != nil {
setTooltip(state.Label().String())
}
})
}