2021-01-10 21:52:29 +01:00
|
|
|
package tui
|
|
|
|
|
|
|
|
type Events interface {
|
2022-04-02 13:01:41 +02:00
|
|
|
|
2022-04-03 16:29:01 +02:00
|
|
|
// OnKeyPressed is called every time a key or key-combination is pressed.
|
|
|
|
// If OnKeyPressed returns true, the event will not be passed onto child views
|
2022-04-01 20:10:51 +02:00
|
|
|
OnKeyPressed(event *KeyEvent) (consumed bool)
|
2022-04-03 16:29:01 +02:00
|
|
|
|
2022-05-04 14:16:08 +02:00
|
|
|
// OnMouseEvent is called every time the mouse was used in any way.
|
|
|
|
// That includes mouse movement, button presses and scroll wheel usage
|
2022-04-03 16:29:01 +02:00
|
|
|
// If OnMouseClicked returns true, the event will not be passed onto child views
|
2022-05-04 14:16:08 +02:00
|
|
|
OnMouseEvent(event *MouseEvent) (consumed bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
type EventTmpl struct {
|
|
|
|
KeyPressed func(event *KeyEvent) (consumed bool)
|
|
|
|
MouseEvent func(event *MouseEvent) (consumed bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Events = &EventTmpl{}
|
|
|
|
|
|
|
|
func (e *EventTmpl) OnKeyPressed(event *KeyEvent) (consumed bool) {
|
|
|
|
if e.KeyPressed == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return e.KeyPressed(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *EventTmpl) OnMouseEvent(event *MouseEvent) (consumed bool) {
|
|
|
|
if e.MouseEvent == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return e.MouseEvent(event)
|
2021-01-10 21:52:29 +01:00
|
|
|
}
|