tins2020/iconbutton.go

48 lines
1020 B
Go
Raw Normal View History

package tins2020
2020-05-14 06:29:23 +00:00
import (
2020-05-23 07:11:08 +00:00
"image/color"
"opslag.de/schobers/zntg"
2020-05-17 08:56:56 +00:00
"opslag.de/schobers/zntg/ui"
2020-05-14 06:29:23 +00:00
)
type IconButton struct {
2020-05-17 08:56:56 +00:00
ui.Button
2020-05-23 07:11:08 +00:00
Active bool
}
2020-05-17 08:56:56 +00:00
func NewIconButton(icon string, click ui.EventEmptyFn) *IconButton {
b := &IconButton{
Button: ui.Button{
2020-05-23 07:11:08 +00:00
Icon: icon,
IconHeight: 48,
Type: ui.ButtonTypeText,
HoverColor: hoverTransparentColor,
},
}
2020-05-23 07:11:08 +00:00
b.Font.Color = color.White
b.ButtonClicked().AddHandler(func(ctx ui.Context, _ ui.ControlClickedArgs) { click(ctx) })
2020-05-17 08:56:56 +00:00
return b
}
2020-05-17 08:56:56 +00:00
func NewIconButtonConfigure(icon string, click ui.EventEmptyFn, configure func(*IconButton)) *IconButton {
button := NewIconButton(icon, click)
configure(button)
return button
}
2020-05-23 07:11:08 +00:00
var hoverTransparentColor = zntg.MustHexColor(`#FFFFFF1F`)
2020-05-17 08:56:56 +00:00
2020-05-23 07:11:08 +00:00
func (b *IconButton) Render(ctx ui.Context) {
b.RenderActive(ctx)
b.Button.Render(ctx)
}
2020-05-17 08:56:56 +00:00
2020-05-23 07:11:08 +00:00
func (b *IconButton) RenderActive(ctx ui.Context) {
if b.Active && !b.Disabled && !b.IsOver() {
ctx.Renderer().FillRectangle(b.Bounds(), hoverTransparentColor)
}
}