-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.go
113 lines (92 loc) · 2.3 KB
/
GUI.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
105
106
107
108
109
110
111
112
113
/* GUI.go © Penguin_Spy 2024
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package main
import (
"image"
"log"
g "github.com/AllenDang/giu"
)
func onClickMe() {
log.Println("Hello world!")
}
type FullImageWidget struct {
id string
image image.Image
}
func FullImage(id string, image image.Image) *FullImageWidget {
return &FullImageWidget{
id: id,
image: image,
}
}
func (w *FullImageWidget) Build() {
width, _ := g.GetAvailableRegion()
bounds := w.image.Bounds()
height := float32(bounds.Dy()) * (width / float32(bounds.Dx()))
g.ImageWithRgba(w.image).
ID("FullImage##"+w.id).
Size(width, height).
Build()
}
func gameList() []g.Widget {
items := make([]g.Widget, len(games))
for i, game := range games {
name := game.name
items[i] = g.Button(name).OnClick(func() {
log.Printf("button for %s clicked: %v\n", game.name, game)
viewingGame = game
})
}
return items
}
func gameView(game *game) g.Widget {
return g.Column(
FullImage(game.id, game.hero),
g.Label(game.name).Font(fonts["header"]),
g.Button("Click Me").OnClick(onClickMe),
g.Button("I'm so cute").OnClick(func() {
callOnPlay(game)
}),
)
}
var wnd *g.MasterWindow
var split float32 = 200
type GUIState int
const (
guiStateLoading GUIState = iota
guiStateGame
)
var guiState GUIState = guiStateLoading
var viewingGame *game
func loop() {
switch guiState {
case guiStateLoading:
g.SingleWindow().Layout(
g.Align(g.AlignCenter).To(g.Label("loading...").Font(fonts["header"])),
)
case guiStateGame:
var mainContent g.Widget
if viewingGame != nil {
mainContent = gameView(viewingGame)
} else {
mainContent = g.Align(g.AlignCenter).To(g.Label("no game selected").Font(fonts["header"]))
}
g.SingleWindow().Layout(
g.SplitLayout(g.DirectionVertical, &split,
g.Column(gameList()...),
g.Column(mainContent),
),
)
}
}
var fonts = make(map[string]*g.FontInfo)
func GUI_start() {
wnd = g.NewMasterWindow("Pylon Launcher", 900, 600, 0)
g.Context.FontAtlas.SetDefaultFont("fonts/Montserrat-Regular.ttf", 18)
fonts["header"] = g.Context.FontAtlas.AddFont("fonts/MontserratAlternates-Regular.ttf", 48)
wnd.Run(loop)
}