1 package etk 2 3 import ( 4 "image" 5 "image/color" 6 7 "github.com/hajimehoshi/ebiten/v2" 8 ) 9 10 // Widget represents an interface element. Most widgets will embed Box and build 11 // on top of it. 12 type Widget interface { 13 // Rect returns the position and size of the widget. 14 Rect() image.Rectangle 15 16 // SetRect sets the position and size of the widget. 17 SetRect(r image.Rectangle) 18 19 // Background returns the background color of the widget. 20 Background() color.RGBA 21 22 // SetBackground sets the background color of the widget. 23 SetBackground(background color.RGBA) 24 25 // Focus returns the focus state of the widget. 26 Focus() bool 27 28 // SetFocus sets the focus state of the widget. 29 SetFocus(focus bool) (accept bool) 30 31 // Visible returns the visibility of the widget. 32 Visible() bool 33 34 // SetVisible sets the visibility of the widget. 35 SetVisible(visible bool) 36 37 // HandleKeyboard is called when a keyboard event occurs. 38 HandleKeyboard(ebiten.Key, rune) (handled bool, err error) 39 40 // HandleMouse is called when a mouse event occurs. Only mouse events that 41 // are on top of the widget are passed to the widget. 42 HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error) 43 44 // Draw draws the widget on the screen. 45 Draw(screen *ebiten.Image) error 46 47 // Children returns the children of the widget. Children are drawn in the 48 // order they are returned. Keyboard and mouse events are passed to children 49 // in reverse order. 50 Children() []Widget 51 } 52 53 // ignoreMouse wraps a widget to ignore mouse events. 54 type ignoreMouse struct { 55 Widget 56 } 57 58 // HandleMouse is called when a mouse event occurs. Only mouse events that 59 // are on top of the widget are passed to the widget. 60 func (i *ignoreMouse) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error) { 61 return false, nil 62 } 63