/
more_page.go
140 lines (125 loc) · 3.38 KB
/
more_page.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
package page
import (
"gioui.org/layout"
"gioui.org/widget"
"github.com/planetdecred/godcr/ui/load"
"github.com/planetdecred/godcr/ui/page/components"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/values"
)
const MorePageID = "More"
type morePageHandler struct {
clickable *widget.Clickable
image *decredmaterial.Image
page string
action func()
}
type MorePage struct {
*load.Load
container layout.Flex
morePageListItems []morePageHandler
}
func NewMorePage(l *load.Load) *MorePage {
morePageListItems := []morePageHandler{
{
clickable: new(widget.Clickable),
image: l.Icons.SettingsIcon,
page: SettingsPageID,
action: func() {
l.ChangeFragment(NewSettingsPage(l))
},
},
{
clickable: new(widget.Clickable),
image: l.Icons.SecurityIcon,
page: SecurityToolsPageID,
action: func() {
l.ChangeFragment(NewSecurityToolsPage(l))
},
},
{
clickable: new(widget.Clickable),
image: l.Icons.HelpIcon,
page: HelpPageID,
action: func() {
l.ChangeFragment(NewHelpPage(l))
},
},
{
clickable: new(widget.Clickable),
image: l.Icons.AboutIcon,
page: AboutPageID,
action: func() {
l.ChangeFragment(NewAboutPage(l))
},
},
{
clickable: new(widget.Clickable),
image: l.Icons.DebugIcon,
page: DebugPageID,
action: func() {
l.ChangeFragment(NewDebugPage(l))
},
},
}
pg := &MorePage{
container: layout.Flex{Axis: layout.Vertical},
morePageListItems: morePageListItems,
Load: l,
}
return pg
}
func (pg *MorePage) ID() string {
return MorePageID
}
func (pg *MorePage) OnResume() {
}
func (pg *MorePage) Handle() {
for _, item := range pg.morePageListItems {
for item.clickable.Clicked() {
item.action()
}
}
}
func (pg *MorePage) OnClose() {}
func (pg *MorePage) Layout(gtx layout.Context) layout.Dimensions {
container := func(gtx C) D {
pg.layoutMoreItems(gtx)
return layout.Dimensions{Size: gtx.Constraints.Max}
}
return components.UniformPadding(gtx, container)
}
func (pg *MorePage) layoutMoreItems(gtx layout.Context) layout.Dimensions {
list := layout.List{Axis: layout.Vertical}
return list.Layout(gtx, len(pg.morePageListItems), func(gtx C, i int) D {
return layout.Inset{Bottom: values.MarginPadding8}.Layout(gtx, func(gtx C) D {
return decredmaterial.Clickable(gtx, pg.morePageListItems[i].clickable, func(gtx C) D {
return decredmaterial.LinearLayout{Orientation: layout.Horizontal,
Width: decredmaterial.MatchParent,
Height: decredmaterial.WrapContent,
Background: pg.Theme.Color.Surface,
Shadow: pg.Theme.Shadow(),
Border: decredmaterial.Border{Radius: decredmaterial.Radius(14)},
Padding: layout.UniformInset(values.MarginPadding15)}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Center.Layout(gtx, pg.morePageListItems[i].image.Layout24dp)
}),
layout.Rigid(func(gtx C) D {
return layout.Inset{
Left: values.MarginPadding15,
Top: values.MarginPadding2,
}.Layout(gtx, func(gtx C) D {
return layout.Center.Layout(gtx, func(gtx C) D {
page := pg.morePageListItems[i].page
if page == SecurityToolsPageID {
page = "Security Tools"
}
return pg.Theme.Body1(page).Layout(gtx)
})
})
}),
)
})
})
})
}