2020-05-10 15:16:18 +00:00
|
|
|
package tins2020
|
|
|
|
|
2020-05-14 06:29:23 +00:00
|
|
|
import (
|
2020-05-17 08:56:56 +00:00
|
|
|
"opslag.de/schobers/zntg/ui"
|
2020-05-14 06:29:23 +00:00
|
|
|
)
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
// import (
|
|
|
|
// "github.com/veandco/go-sdl2/sdl"
|
|
|
|
// )
|
2020-05-11 09:44:50 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
// type HoverEffect int
|
|
|
|
|
|
|
|
// const (
|
|
|
|
// HoverEffectLigthen HoverEffect = iota
|
|
|
|
// HoverEffectColor
|
|
|
|
// )
|
2020-05-11 09:44:50 +00:00
|
|
|
|
2020-05-10 15:16:18 +00:00
|
|
|
type IconButton struct {
|
2020-05-17 08:56:56 +00:00
|
|
|
ui.Button
|
2020-05-10 15:16:18 +00:00
|
|
|
|
|
|
|
IconDisabled string
|
2020-05-10 21:00:19 +00:00
|
|
|
IconHeight int32
|
2020-05-17 08:56:56 +00:00
|
|
|
// IconScale Scale
|
|
|
|
// IconWidth int32
|
2020-05-10 15:16:18 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
// IconActive HoverEffect
|
|
|
|
// IconHover HoverEffect
|
2020-05-11 09:44:50 +00:00
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
// Tooltip Tooltip
|
2020-05-11 13:38:34 +00:00
|
|
|
IsActive bool
|
2020-05-10 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func NewIconButton(icon string, click ui.EventEmptyFn) *IconButton {
|
|
|
|
b := &IconButton{
|
|
|
|
Button: ui.Button{
|
|
|
|
Icon: icon,
|
2020-05-10 15:16:18 +00:00
|
|
|
},
|
|
|
|
}
|
2020-05-17 08:56:56 +00:00
|
|
|
b.ControlClicked().AddHandler(func(ctx ui.Context, _ ui.ControlClickedArgs) { click(ctx) })
|
|
|
|
return b
|
2020-05-10 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func NewIconButtonConfigure(icon string, click ui.EventEmptyFn, configure func(*IconButton)) *IconButton {
|
|
|
|
button := NewIconButton(icon, click)
|
2020-05-10 15:16:18 +00:00
|
|
|
configure(button)
|
|
|
|
return button
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
// func (b *IconButton) activeTexture(ctx ui.Context) *Texture {
|
|
|
|
// if b.Disabled {
|
|
|
|
// texture := ctx.Textures.Texture(b.IconDisabled)
|
|
|
|
// if texture != nil {
|
|
|
|
// return texture
|
|
|
|
// }
|
|
|
|
|
|
|
|
// texture = ctx.Textures.Texture(b.Icon)
|
|
|
|
// if len(b.IconDisabled) == 0 {
|
|
|
|
// return texture
|
|
|
|
// }
|
|
|
|
// color, err := HexColor(b.IconDisabled)
|
|
|
|
// if err == nil {
|
|
|
|
// texture.SetColor(color)
|
|
|
|
// }
|
|
|
|
// return texture
|
|
|
|
// }
|
|
|
|
// return ctx.Textures.Texture(b.Icon)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// func (b *IconButton) Arrange(ctx ui.Context, bounds Rectangle) {
|
|
|
|
// b.ControlBase.Arrange(ctx, bounds)
|
|
|
|
// b.Tooltip.Arrange(ctx, bounds)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// func (b *IconButton) Handle(ctx ui.Context, event sdl.Event) bool {
|
|
|
|
// if b.ControlBase.Handle(ctx, event) {
|
|
|
|
// return true
|
|
|
|
// }
|
|
|
|
// if b.Tooltip.Handle(ctx, event) {
|
|
|
|
// return true
|
|
|
|
// }
|
|
|
|
// return false
|
|
|
|
// }
|
|
|
|
|
|
|
|
// func (b *IconButton) Init(ctx ui.Context) error {
|
|
|
|
// if err := b.ControlBase.Init(ctx); err != nil {
|
|
|
|
// return err
|
|
|
|
// }
|
|
|
|
// if err := b.Tooltip.Init(ctx); err != nil {
|
|
|
|
// return err
|
|
|
|
// }
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
|
|
|
|
// func (b *IconButton) Render(ctx ui.Context) {
|
|
|
|
// iconTexture := b.activeTexture(ctx)
|
|
|
|
|
|
|
|
// hover := b.IsMouseOver && !b.Disabled
|
|
|
|
// if (hover && b.IconHover == HoverEffectColor) || (b.IsActive && b.IconActive == HoverEffectColor) {
|
|
|
|
// iconTexture.SetColor(MustHexColor("#15569F"))
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if b.IconScale == ScaleCenter {
|
|
|
|
// size := iconTexture.Size()
|
|
|
|
// if b.IconWidth != 0 {
|
|
|
|
// size = Pt(b.IconWidth, b.IconWidth*size.Y/size.X)
|
|
|
|
// } else if b.IconHeight != 0 {
|
|
|
|
// size = Pt(b.IconHeight*size.X/size.Y, b.IconHeight)
|
|
|
|
// }
|
|
|
|
// iconTexture.CopyResize(ctx.Renderer, Rect(b.Bounds.X+(b.Bounds.W-size.X)/2, b.Bounds.Y+(b.Bounds.H-size.Y)/2, size.X, size.Y))
|
|
|
|
// } else {
|
|
|
|
// iconTexture.CopyResize(ctx.Renderer, b.Bounds)
|
|
|
|
// }
|
|
|
|
// if (hover && b.IconHover == HoverEffectLigthen) || (b.IsActive && b.IconActive == HoverEffectLigthen) {
|
|
|
|
// SetDrawColor(ctx.Renderer, TransparentWhite)
|
|
|
|
// ctx.Renderer.FillRect(b.Bounds.SDLPtr())
|
|
|
|
// }
|
|
|
|
// iconTexture.SetColor(White)
|
|
|
|
|
|
|
|
// if len(b.Tooltip.Text) > 0 && b.IsMouseOver {
|
|
|
|
// b.Tooltip.Render(ctx)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// type Scale int
|
|
|
|
|
|
|
|
// const (
|
|
|
|
// ScaleCenter Scale = iota
|
|
|
|
// ScaleStretch
|
|
|
|
// )
|