button.go
func (b *Button) ProcessEvent(event Event) bool {
	if !b.Enabled() {
		return false
	}

	if event.Type == EventKey {
		if event.Key == term.KeySpace && b.isPressed() == 0 {
			b.setPressed(1)
			ev := Event{Type: EventRedraw}

			go func() {
				PutEvent(ev)
				time.Sleep(100 * time.Millisecond)
				b.setPressed(0)
				PutEvent(ev)
			}()

			if b.onClick != nil {
				b.onClick(event)
			}
			return true
		} else if event.Key == term.KeyEsc && b.isPressed() != 0 {
			b.setPressed(0)
			ReleaseEvents()
			return true
		}
	} else if event.Type == EventMouse {
		if event.Key == term.MouseLeft {
			b.setPressed(1)
			GrabEvents(b)
			return true
		} else if event.Key == term.MouseRelease && b.isPressed() != 0 {
			ReleaseEvents()
			if event.X >= b.x && event.Y >= b.y && event.X < b.x+b.width && event.Y < b.y+b.height {
				if b.onClick != nil {
					b.onClick(event)
				}
			}
			b.setPressed(0)
			return true
		}
	}

	return false
}
func (b *Button) ProcessEvent(event Event) bool {
	if !b.Enabled() {
		return false
	}

	if event.Type == EventKey {
		if event.Key == term.KeySpace && b.isPressed() == 0 {
			b.setPressed(1)
			ev := Event{Type: EventRedraw}

			go func() {
				PutEvent(ev)
				time.Sleep(100 * time.Millisecond)
				b.setPressed(0)
				PutEvent(ev)
			}()

			if b.onClick != nil {
				b.onClick(event)
			}
			return true
		} else if event.Key == term.KeyEsc && b.isPressed() != 0 {
			b.setPressed(0)
			ReleaseEvents()
			return true
		}
	} else if event.Type == EventMouse {
		if event.Key == term.MouseLeft {
			b.setPressed(1)
			GrabEvents(b)
			return true
		} else if event.Key == term.MouseRelease && b.isPressed() != 0 {
			ReleaseEvents()
			if event.X >= b.x && event.Y >= b.y && event.X < b.x+b.width && event.Y < b.y+b.height {
				if b.onClick != nil {
					b.onClick(event)
				}
			}
			b.setPressed(0)
			return true
		}
	}

	return false
}
func ( b * Button ) ProcessEvent ( event Event ) bool { if ! b . Enabled ( ) { return false } if event . Type == EventKey { if event . Key == term . KeySpace && b . isPressed ( ) == 0 { b . setPressed ( 1 ) ev := Event { Type : EventRedraw } go func ( ) { PutEvent ( ev ) time . Sleep ( 100 * time . Millisecond ) b . setPressed ( 0 ) PutEvent ( ev ) } ( ) if b . onClick != nil { b . onClick ( event ) } return true } else if event . Key == term . KeyEsc && b . isPressed ( ) != 0 { b . setPressed ( 0 ) ReleaseEvents ( ) return true } } else if event . Type == EventMouse { if event . Key == term . MouseLeft { b . setPressed ( 1 ) GrabEvents ( b ) return true } else if event . Key == term . MouseRelease && b . isPressed ( ) != 0 { ReleaseEvents ( ) if event . X >= b . x && event . Y >= b . y && event . X < b . x + b . width && event . Y < b . y + b . height { if b . onClick != nil { b . onClick ( event ) } } b . setPressed ( 0 ) return true } } return false }
/*
ProcessEvent processes all events come from the control parent. If a control
processes an event it should return true. If the method returns false it means
that the control do not want or cannot process the event and the caller sends
the event to the control parent
*/
/ * ProcessEvent processes all events come from the control parent . If a control processes an event it should return true . If the method returns false it means that the control do not want or cannot process the event and the caller sends the event to the control parent