48 lines
1021 B
Go
48 lines
1021 B
Go
package tins2020
|
|
|
|
import (
|
|
"image/color"
|
|
|
|
"opslag.de/schobers/zntg"
|
|
"opslag.de/schobers/zntg/ui"
|
|
)
|
|
|
|
type IconButton struct {
|
|
ui.Button
|
|
|
|
Active bool
|
|
}
|
|
|
|
func NewIconButton(icon string, click ui.EventEmptyFn) *IconButton {
|
|
b := &IconButton{
|
|
Button: ui.Button{
|
|
Icon: icon,
|
|
IconHeight: 48,
|
|
Type: ui.ButtonTypeText,
|
|
HoverColor: hoverTransparentColor,
|
|
},
|
|
}
|
|
b.Font.Color = color.White
|
|
b.ButtonClicked().AddHandler(func(ctx ui.Context, _ ui.ControlClickedArgs) { click(ctx) })
|
|
return b
|
|
}
|
|
|
|
func NewIconButtonConfigure(icon string, click ui.EventEmptyFn, configure func(*IconButton)) *IconButton {
|
|
button := NewIconButton(icon, click)
|
|
configure(button)
|
|
return button
|
|
}
|
|
|
|
var hoverTransparentColor = zntg.MustHexColor(`#FFFFFF1F`)
|
|
|
|
func (b *IconButton) Render(ctx ui.Context) {
|
|
b.RenderActive(ctx)
|
|
b.Button.Render(ctx)
|
|
}
|
|
|
|
func (b *IconButton) RenderActive(ctx ui.Context) {
|
|
if b.Active || (!b.Disabled && b.IsOver()) {
|
|
ctx.Renderer().FillRectangle(b.Bounds(), hoverTransparentColor)
|
|
}
|
|
}
|