From 8236b65c06ac83200a1f963f5f2e94644edf2198 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Mon, 11 May 2020 15:38:34 +0200 Subject: [PATCH] No click event is generated when control is disabled. --- control.go | 3 ++- iconbutton.go | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/control.go b/control.go index c4b43d5..b7cf6f4 100644 --- a/control.go +++ b/control.go @@ -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: diff --git a/iconbutton.go b/iconbutton.go index 32703f6..71f3768 100644 --- a/iconbutton.go +++ b/iconbutton.go @@ -19,8 +19,7 @@ type IconButton struct { IconActive HoverEffect IconHover HoverEffect - IsActive bool - IsDisabled bool + IsActive bool } func NewIconButton(icon string, onClick EventContextFn) *IconButton {