2018-03-28 02:01:35 +08:00
|
|
|
// Package widget defines the API of a widget on the dashboard.
|
|
|
|
package widget
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mum4k/termdash/canvas"
|
|
|
|
"github.com/mum4k/termdash/keyboard"
|
|
|
|
"github.com/mum4k/termdash/mouse"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Options contains registration options for a widget.
|
|
|
|
// This is how the widget indicates its needs to the infrastructure.
|
|
|
|
type Options struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Widget is a single widget on the dashboard.
|
2018-03-29 02:34:20 +08:00
|
|
|
// Implementations must be thread safe.
|
2018-03-28 02:01:35 +08:00
|
|
|
type Widget interface {
|
2018-03-29 02:34:20 +08:00
|
|
|
// When the infrastructure calls Draw(), the widget must block on the call
|
|
|
|
// until it finishes drawing onto the provided canvas. When given the
|
|
|
|
// canvas, the widget must first determine its size by calling
|
|
|
|
// Canvas.Size(), then limit all its drawing to this area.
|
|
|
|
//
|
|
|
|
// The widget must not assume that the size of the canvas or its content
|
|
|
|
// remains the same between calls.
|
2018-03-28 02:01:35 +08:00
|
|
|
Draw(canvas *canvas.Canvas) error
|
|
|
|
|
|
|
|
// Keyboard is called when the widget is focused on the dashboard and a key
|
|
|
|
// shortcut the widget registered for was pressed. Only called if the widget
|
|
|
|
// registered for keyboard events.
|
2018-04-05 11:02:43 +08:00
|
|
|
Keyboard(s *keyboard.Key) error
|
2018-03-28 02:01:35 +08:00
|
|
|
|
|
|
|
// Mouse is called when the widget is focused on the dashboard and a mouse
|
|
|
|
// event happens on its canvas. Only called if the widget registered for mouse
|
|
|
|
// events.
|
|
|
|
Mouse(m *mouse.Button) error
|
|
|
|
|
|
|
|
// Options returns registration options for the widget.
|
|
|
|
// This is how the widget indicates to the infrastructure whether it is
|
|
|
|
// interested in keyboard or mouse shortcuts, what is its minimum canvas
|
|
|
|
// size, etc.
|
|
|
|
Options() *Options
|
|
|
|
}
|