-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
119 lines (97 loc) · 3.02 KB
/
ui.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
package main
import (
"fmt"
"os"
"fyne.io/fyne/v2"
fynecontainer "fyne.io/fyne/v2/container"
fynetheme "fyne.io/fyne/v2/theme"
fynewidget "fyne.io/fyne/v2/widget"
"github.com/reiver/nextsocial-app/icons"
"github.com/reiver/nextsocial-app/pages"
)
type UI struct {
container *fyne.Container
pageAccount fyne.CanvasObject
pageHome fyne.CanvasObject
pageMenu fyne.CanvasObject
pageNew fyne.CanvasObject
pageNotifications fyne.CanvasObject
pageSearch fyne.CanvasObject
}
func (receiver *UI) Content() fyne.CanvasObject {
return receiver.container
}
func (receiver *UI) Init() {
if nil == receiver {
return
}
receiver.pageAccount = pages.Account()
receiver.pageHome = pages.Home()
receiver.pageMenu = pages.Menu()
receiver.pageNew = pages.New()
receiver.pageNotifications = pages.Notifications()
receiver.pageSearch = pages.Search()
var content *fyne.Container
{
var label *fynewidget.Label = fynewidget.NewLabel("NextSocial 💬")
var toolbar *fynewidget.Toolbar = fynewidget.NewToolbar(
fynewidget.NewToolbarAction(icons.Account(), receiver.ShowPageAccount),
fynewidget.NewToolbarSpacer(),
fynewidget.NewToolbarAction(icons.Search(), receiver.ShowPageSearch),
fynewidget.NewToolbarSpacer(),
fynewidget.NewToolbarAction(icons.Menu(), receiver.ShowPageMenu),
fynewidget.NewToolbarSpacer(),
fynewidget.NewToolbarAction(icons.Notifications(), receiver.ShowPageNotifications),
fynewidget.NewToolbarSpacer(),
fynewidget.NewToolbarAction(icons.Home(), receiver.ShowPageHome),
fynewidget.NewToolbarSeparator(),
fynewidget.NewToolbarAction(fynetheme.DocumentCreateIcon(), receiver.ShowPageNew),
)
content = fynecontainer.NewBorder(nil, toolbar, nil, nil, label)
}
receiver.container = content
}
func (receiver *UI) showPage(canvasObject fyne.CanvasObject) {
if nil == receiver {
fmt.Fprintln(os.Stderr, "[show-page] nil receiver")
return
}
if nil == canvasObject {
fmt.Fprintln(os.Stderr, "[show-page] nil fyne canvas-object")
return
}
container := receiver.container
if nil == container {
fmt.Fprintln(os.Stderr, "[show-page] nil fyne container")
return
}
if len(container.Objects) <= 0 {
fmt.Fprintln(os.Stderr, "[show-page] no fyne container objects")
return
}
container.Objects[0] = canvasObject
}
func (receiver *UI) ShowPageAccount() {
fmt.Println("show page 'account'")
receiver.showPage(receiver.pageAccount)
}
func (receiver *UI) ShowPageHome() {
fmt.Println("show page 'home'")
receiver.showPage(receiver.pageHome)
}
func (receiver *UI) ShowPageMenu() {
fmt.Println("show page 'menu'")
receiver.showPage(receiver.pageMenu)
}
func (receiver *UI) ShowPageNew() {
fmt.Println("show page 'new'")
receiver.showPage(receiver.pageNew)
}
func (receiver *UI) ShowPageNotifications() {
fmt.Println("show page 'notifications'")
receiver.showPage(receiver.pageNotifications)
}
func (receiver *UI) ShowPageSearch() {
fmt.Println("show page 'search'")
receiver.showPage(receiver.pageSearch)
}