-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
144 lines (117 loc) · 3.39 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"net/url"
_ "image/jpeg"
_ "image/png"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"github.com/gusti-andika/movie.go/background"
"github.com/gusti-andika/movie.go/config"
"github.com/gusti-andika/movie.go/data"
"github.com/gusti-andika/movie.go/genre"
"github.com/gusti-andika/movie.go/widgetx"
)
var (
topWindow fyne.Window
contentView *fyne.Container
breadcrumb *widgetx.Breadcrumb
)
func main() {
a := app.New()
w := a.NewWindow("Movies")
topWindow = w
nav := data.TreeData{}
genres, err := genre.List()
if err != nil {
panic(err)
}
nav.Init(genres)
navView := createNavigatorView(&nav)
//contentView = container.NewGridWithColumns(2)
_container := container.NewMax(createMainView())
split := container.NewHSplit(navView, _container)
split.Offset = 0.2
w.SetContent(split)
w.SetMaster()
w.Resize(fyne.NewSize(640, 460))
go background.RefreshImage()
w.ShowAndRun()
}
func createMainView() fyne.CanvasObject {
breadcrumb = widgetx.NewBreadcrumb("Movie Golang App", func() {
contentView.Objects = []fyne.CanvasObject{welcomeScreen()}
contentView.Refresh()
})
top := container.NewVBox(breadcrumb.Container, widget.NewSeparator())
contentView = container.NewGridWithColumns(2)
contentView.Objects = []fyne.CanvasObject{welcomeScreen()}
contentView.Refresh()
return container.NewBorder(top, nil, nil, nil, container.NewVScroll(contentView))
}
func createNavigatorView(nav *data.TreeData) fyne.CanvasObject {
tree := &widget.Tree{
ChildUIDs: func(uid string) []string {
return (*nav).Uids[uid]
},
IsBranch: func(uid string) bool {
children, ok := (*nav).Uids[uid]
return ok && len(children) > 0
},
CreateNode: func(branch bool) fyne.CanvasObject {
return widget.NewLabel("Collection Widgets")
},
UpdateNode: func(uid string, branch bool, obj fyne.CanvasObject) {
t, ok := (*nav).Nodes[uid]
if !ok {
fyne.LogError("Missing genre: "+uid, nil)
return
}
obj.(*widget.Label).SetText(t.NodeName())
},
OnSelected: func(uid string) {
if t, ok := (*nav).Nodes[uid]; ok {
if _, ok := (*nav).Uids[uid]; !ok {
selectGenre(t.(genre.Genre))
}
}
},
}
top := container.NewVBox(widget.NewLabel("GENRES"), widget.NewSeparator())
return container.NewBorder(top, nil, nil, nil, tree)
}
func parseURL(urlStr string) *url.URL {
link, err := url.Parse(urlStr)
if err != nil {
fyne.LogError("Could not parse URL", err)
}
return link
}
func welcomeScreen() fyne.CanvasObject {
return container.NewCenter(container.NewVBox(
widget.NewLabelWithStyle("Welcome to golang Movie Catalog", fyne.TextAlignCenter, fyne.TextStyle{Bold: true}),
container.NewHBox(
widget.NewHyperlink("fyne.io", parseURL("https://fyne.io/")),
widget.NewLabel("-"),
widget.NewHyperlink("themoviedb.org", parseURL("https://developers.themoviedb.org")),
),
))
}
func selectGenre(g genre.Genre) {
m, _ := g.Movies()
cards := []fyne.CanvasObject{}
contentView.Objects = []fyne.CanvasObject{widget.NewProgressBarInfinite()}
contentView.Refresh()
for _, mm := range m {
desc := widget.NewLabel(mm.Desc)
desc.Wrapping = fyne.TextWrapWord
card := widget.NewCard(mm.Title, "", desc)
imageStr, _ := config.ImageURL(mm.Poster)
background.LoadImage(imageStr, card)
cards = append(cards, card)
}
breadcrumb.SetGenre(g.Name)
contentView.Objects = cards
contentView.Refresh()
}