It is no longer possible to activate disabled buttons

This commit is contained in:
Sasha Koshka 2023-01-18 11:58:42 -05:00
parent 36c5ed40e9
commit 873336e029

View File

@ -35,6 +35,7 @@ func (element *Button) Resize (width, height int) {
} }
func (element *Button) HandleMouseDown (x, y int, button tomo.Button) { func (element *Button) HandleMouseDown (x, y int, button tomo.Button) {
if !element.enabled { return }
element.Select() element.Select()
if button != tomo.ButtonLeft { return } if button != tomo.ButtonLeft { return }
element.pressed = true element.pressed = true
@ -55,6 +56,7 @@ func (element *Button) HandleMouseUp (x, y int, button tomo.Button) {
within := image.Point { x, y }. within := image.Point { x, y }.
In(element.Bounds()) In(element.Bounds())
if !element.enabled { return }
if within && element.onClick != nil { if within && element.onClick != nil {
element.onClick() element.onClick()
} }
@ -68,6 +70,7 @@ func (element *Button) HandleKeyDown (
modifiers tomo.Modifiers, modifiers tomo.Modifiers,
repeated bool, repeated bool,
) { ) {
if !element.enabled { return }
if key == tomo.KeyEnter { if key == tomo.KeyEnter {
element.pressed = true element.pressed = true
if element.core.HasImage() { if element.core.HasImage() {
@ -84,6 +87,7 @@ func (element *Button) HandleKeyUp(key tomo.Key, modifiers tomo.Modifiers) {
element.draw() element.draw()
element.core.PushAll() element.core.PushAll()
} }
if !element.enabled { return }
if element.onClick != nil { if element.onClick != nil {
element.onClick() element.onClick()
} }
@ -95,6 +99,7 @@ func (element *Button) Selected () (selected bool) {
} }
func (element *Button) Select () { func (element *Button) Select () {
if !element.enabled { return }
element.core.RequestSelection() element.core.RequestSelection()
} }