No click event is generated when control is disabled.

This commit is contained in:
Sander Schobers 2020-05-11 15:38:34 +02:00
parent 1008b7b34b
commit 8236b65c06
2 changed files with 3 additions and 3 deletions

View File

@ -22,6 +22,7 @@ func EmptyEvent(fn EventFn) EventContextFn {
type ControlBase struct {
Bounds Rectangle
IsDisabled bool
IsMouseOver bool
OnLeftMouseButtonClick EventContextFn
@ -36,7 +37,7 @@ func (b *ControlBase) Handle(ctx *Context, event sdl.Event) bool {
case *sdl.MouseMotionEvent:
b.IsMouseOver = b.Bounds.IsPointInside(e.X, e.Y)
case *sdl.MouseButtonEvent:
if b.IsMouseOver && e.Button == sdl.BUTTON_LEFT && e.Type == sdl.MOUSEBUTTONDOWN {
if !b.IsDisabled && b.IsMouseOver && e.Button == sdl.BUTTON_LEFT && e.Type == sdl.MOUSEBUTTONDOWN {
return b.Invoke(ctx, b.OnLeftMouseButtonClick)
}
case *sdl.WindowEvent:

View File

@ -19,8 +19,7 @@ type IconButton struct {
IconActive HoverEffect
IconHover HoverEffect
IsActive bool
IsDisabled bool
IsActive bool
}
func NewIconButton(icon string, onClick EventContextFn) *IconButton {