/
sub_page.go
186 lines (169 loc) · 5.32 KB
/
sub_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package components
import (
"gioui.org/layout"
"gioui.org/widget"
"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/load"
"github.com/crypto-power/cryptopower/ui/modal"
"github.com/crypto-power/cryptopower/ui/utils"
"github.com/crypto-power/cryptopower/ui/values"
)
type SubPage struct {
*load.Load
Title string
SubTitle string
Back func()
Body layout.Widget
InfoTemplate string
ExtraItem *cryptomaterial.Clickable
Extra layout.Widget
ExtraText string
HandleExtra func()
ExtraHeader layout.Widget
BackButton cryptomaterial.IconButton
InfoButton cryptomaterial.IconButton
}
func SubpageHeaderButtons(l *load.Load) (cryptomaterial.IconButton, cryptomaterial.IconButton) {
backClickable := new(widget.Clickable)
backButton := l.Theme.NewIconButton(l.Theme.Icons.NavigationArrowBack, backClickable)
infoButton := l.Theme.IconButton(l.Theme.Icons.ActionInfo)
size := values.MarginPadding24
if l.IsMobileView() {
size = values.MarginPadding16
}
backButton.Size, infoButton.Size = size, size
buttonInset := layout.UniformInset(values.MarginPadding0)
backButton.Inset, infoButton.Inset = buttonInset, buttonInset
return backButton, infoButton
}
func GetBackButton(l *load.Load) cryptomaterial.IconButton {
backClickable := new(widget.Clickable)
backButton := l.Theme.NewIconButton(l.Theme.Icons.NavigationArrowBack, backClickable)
size := values.MarginPadding24
if l.IsMobileView() {
size = values.MarginPadding16
}
backButton.Size = size
backButton.Inset = layout.UniformInset(values.MarginPadding0)
l.Theme.AddBackClick(backClickable)
return backButton
}
func (sp *SubPage) Layout(window app.WindowNavigator, gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{Bottom: values.MarginPadding22}.Layout(gtx, func(gtx C) D {
return sp.Header(window, gtx)
})
}),
layout.Rigid(sp.Body),
)
}
func (sp *SubPage) LayoutWithHeadCard(window app.WindowNavigator, gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
horizontalPadding := values.MarginPadding24
if sp.IsMobileView() {
horizontalPadding = 16
}
return sp.Theme.Card().Layout(gtx, func(gtx C) D {
return layout.Inset{
Top: values.MarginPadding16,
Left: horizontalPadding,
Right: horizontalPadding,
}.Layout(gtx, func(gtx C) D {
return sp.Header(window, gtx)
})
})
}),
layout.Rigid(func(gtx C) D {
return layout.Inset{Top: values.MarginPadding8}.Layout(gtx, sp.Body)
}),
)
}
func (sp *SubPage) Header(window app.WindowNavigator, gtx C) D {
sp.EventHandler(window)
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Right: values.MarginPadding4,
}.Layout(gtx, sp.BackButton.Layout)
}),
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(sp.Load.Theme.SemiBoldLabelWithSize(sp.ConvertTextSize(values.TextSize20), sp.Title).Layout),
layout.Rigid(func(gtx C) D {
if !utils.StringNotEmpty(sp.SubTitle) {
return D{}
}
sub := sp.Load.Theme.Label(sp.ConvertTextSize(values.TextSize14), sp.SubTitle)
sub.Color = sp.Load.Theme.Color.GrayText2
return sub.Layout(gtx)
}),
)
}),
layout.Flexed(1, func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
if sp.InfoTemplate != "" {
return sp.InfoButton.Layout(gtx)
} else if sp.ExtraItem == nil {
return D{}
}
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if sp.ExtraText != "" {
return layout.Inset{Right: values.MarginPadding10}.Layout(gtx, sp.Theme.Caption(sp.ExtraText).Layout)
}
return D{}
}),
layout.Rigid(func(gtx C) D {
return sp.ExtraItem.Layout(gtx, sp.Extra)
}),
)
})
}),
)
}),
layout.Rigid(func(gtx C) D {
if sp.ExtraHeader != nil {
return layout.Inset{Top: values.MarginPadding16}.Layout(gtx, sp.ExtraHeader)
}
return D{}
}),
)
}
func (sp *SubPage) CombinedLayout(window app.WindowNavigator, gtx C) D {
return sp.Theme.Card().Layout(gtx, func(gtx C) D {
return layout.Inset{Bottom: values.MarginPadding24}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.UniformInset(values.MarginPadding24).Layout(gtx, func(gtx C) D {
return sp.Header(window, gtx)
})
}),
layout.Rigid(sp.Body),
)
})
})
}
func (sp *SubPage) EventHandler(window app.WindowNavigator) {
if sp.InfoTemplate != "" {
if sp.InfoButton.Button.Clicked() {
infoModal := modal.NewCustomModal(sp.Load).
Title(sp.Title).
SetupWithTemplate(sp.InfoTemplate).
SetContentAlignment(layout.W, layout.W, layout.Center).
SetCancelable(true).
PositiveButtonStyle(sp.Theme.Color.Primary, sp.Theme.Color.Surface)
window.ShowModal(infoModal)
}
}
if sp.BackButton.Button.Clicked() {
sp.Back()
}
if sp.ExtraItem != nil && sp.ExtraItem.Clicked() {
sp.HandleExtra()
}
}