-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwidget.go
54 lines (43 loc) · 1.07 KB
/
widget.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 Hajime Hoshi
package guigui
import (
"github.com/hajimehoshi/ebiten/v2"
)
type Widget interface {
Layout(context *Context, appender *ChildWidgetAppender)
HandleInput(context *Context) HandleInputResult
Update(context *Context) error
CursorShape(context *Context) (ebiten.CursorShapeType, bool)
Draw(context *Context, dst *ebiten.Image)
IsPopup() bool
Size(context *Context) (int, int)
widgetState() *widgetState
}
type HandleInputResult struct {
widget Widget
aborted bool
}
func HandleInputByWidget(widget Widget) HandleInputResult {
return HandleInputResult{
widget: widget,
}
}
func AbortHandlingInput() HandleInputResult {
return HandleInputResult{
aborted: true,
}
}
func (r *HandleInputResult) ShouldRaise() bool {
return r.widget != nil || r.aborted
}
func Parent(widget Widget) Widget {
return widget.widgetState().parent
}
type RootWidget struct {
DefaultWidget
}
func (*RootWidget) Size(context *Context) (int, int) {
bounds := context.app.bounds()
return bounds.Dx(), bounds.Dy()
}