-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
104 lines (88 loc) · 1.9 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"image"
"image/color"
"sync"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/yohamta/furex/v2"
)
type Game struct {
initOnce sync.Once
screen screen
gameUI *furex.View
}
type screen struct {
Width int
Height int
}
func (g *Game) Update() error {
g.initOnce.Do(func() {
g.setupUI()
})
g.gameUI.UpdateWithSize(ebiten.WindowSize())
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
screen.Fill(color.RGBA{0x3d, 0x55, 0x0c, 0xff})
g.gameUI.Draw(screen)
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
g.screen.Width = outsideWidth
g.screen.Height = outsideHeight
return g.screen.Width, g.screen.Height
}
func NewGame() (*Game, error) {
game := &Game{}
return game, nil
}
func (g *Game) setupUI() {
colors := []color.Color{
color.RGBA{0x59, 0x98, 0x1a, 0xff},
color.RGBA{0x81, 0xb6, 0x22, 0xff},
color.RGBA{0xec, 0xf8, 0x7f, 0xff},
}
g.gameUI = &furex.View{
Width: g.screen.Width,
Height: g.screen.Height,
Direction: furex.Row,
Justify: furex.JustifyCenter,
AlignItems: furex.AlignItemCenter,
AlignContent: furex.AlignContentCenter,
Wrap: furex.Wrap,
}
for i := 0; i < 20; i++ {
g.gameUI.AddChild(&furex.View{
Width: 100,
Height: 100,
Handler: &Box{
Color: colors[i%len(colors)],
},
})
}
}
type Box struct {
Color color.Color
}
var _ furex.Drawer = (*Box)(nil)
func (b *Box) Draw(screen *ebiten.Image, frame image.Rectangle, view *furex.View) {
ebitenutil.DrawRect(
screen,
float64(frame.Min.X),
float64(frame.Min.Y),
float64(frame.Size().X),
float64(frame.Size().Y),
b.Color,
)
}
func main() {
ebiten.SetWindowSize(480, 640)
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
game, err := NewGame()
if err != nil {
panic(err)
}
if err := ebiten.RunGame(game); err != nil {
panic(err)
}
}