-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainWindow.go
99 lines (85 loc) · 2.1 KB
/
mainWindow.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
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"skyvillage-launcher-rewrite/auth"
)
var (
mainWindow fyne.Window
)
func InitMainWindow(app fyne.App, close func()) {
mainWindow = app.Driver().CreateWindow("SkyVillage Launcher")
mainWindow.Resize(fyne.Size{
Height: 500,
Width: 450,
})
icon, err := fyne.LoadResourceFromPath("./icon.png")
if err == nil {
mainWindow.SetIcon(icon)
}
mainWindow.CenterOnScreen()
mainWindow.SetFixedSize(true)
mainWindow.SetOnClosed(close)
initContent(&mainWindow)
mainWindow.ShowAndRun()
}
func CloseMainWindow() {
mainWindow.Close()
}
func initContent(ww *fyne.Window) {
w := *ww
if auth.IsLoggedIn() {
w.SetContent(getLoggedInContent())
} else {
w.SetContent(getLoginFormContent())
}
}
func getLoggedInContent() fyne.CanvasObject {
return container.NewVBox(
getLoggedInNewsContent(),
getLoggedInMenuBarContent(),
)
}
func getLoggedInMenuBarContent() fyne.CanvasObject {
return container.NewHBox(
widget.NewLabel("Menu"),
)
}
func getLoggedInNewsContent() fyne.CanvasObject {
return container.NewGridWrap(
fyne.NewSize(440, 400),
container.NewCenter(
widget.NewCard("Hírek", "",
container.NewGridWrap(
fyne.NewSize(400, 300),
widget.NewLabel("Igen"),
),
),
),
)
}
func getLoginFormContent() fyne.CanvasObject {
usernameInput := widget.NewEntry()
usernameInput.Resize(fyne.NewSize(150, 30))
usernameInput.Refresh()
passwordInput := widget.NewPasswordEntry()
passwordInput.SetPlaceHolder("Nem kell megadni")
passwordInput.Resize(fyne.NewSize(150, 30))
form := &widget.Form{
Items: []*widget.FormItem{
{Text: "Felhasználónév", Widget: usernameInput},
{Text: "Jelszó", Widget: passwordInput},
},
OnSubmit: func() {
processLogin(usernameInput.Text, passwordInput.Text)
},
SubmitText: "Bejelentkezés",
}
return container.New(layout.NewCenterLayout(), widget.NewCard(" Bejelentkezés ", " ", form))
}
func processLogin(username, password string) {
auth.Login(username, password)
initContent(&mainWindow)
}