...
1 package etk
2
3 import (
4 "image"
5 "image/color"
6
7 "github.com/hajimehoshi/ebiten/v2"
8 )
9
10
11
12 type Widget interface {
13
14 Rect() image.Rectangle
15
16
17 SetRect(r image.Rectangle)
18
19
20 Background() color.RGBA
21
22
23 SetBackground(background color.RGBA)
24
25
26 Focus() bool
27
28
29 SetFocus(focus bool) (accept bool)
30
31
32 Visible() bool
33
34
35 SetVisible(visible bool)
36
37
38
39 Cursor() ebiten.CursorShapeType
40
41
42 HandleKeyboard(ebiten.Key, rune) (handled bool, err error)
43
44
45
46 HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)
47
48
49 Draw(screen *ebiten.Image) error
50
51
52
53
54 Children() []Widget
55 }
56
57
58 type WithoutFocus struct {
59 Widget
60 }
61
62
63 func (w *WithoutFocus) Focus() bool {
64 return false
65 }
66
67
68 func (w *WithoutFocus) SetFocus(focus bool) (accept bool) {
69 return false
70 }
71
72
73 type WithoutMouse struct {
74 Widget
75 }
76
77
78
79 func (w *WithoutMouse) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error) {
80 return false, nil
81 }
82
83
84
85 type WithoutMouseExceptScroll struct {
86 Widget
87 handleOnce bool
88 }
89
90
91
92 func (w *WithoutMouseExceptScroll) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error) {
93 if pressed || clicked {
94 w.handleOnce = true
95 return w.Widget.HandleMouse(cursor, pressed, clicked)
96 } else if w.handleOnce {
97 w.handleOnce = false
98 return w.Widget.HandleMouse(cursor, pressed, clicked)
99 }
100 return false, nil
101 }
102
View as plain text