/
page.go
632 lines (573 loc) · 23.7 KB
/
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
package ui
import (
"encoding/json"
"image"
"image/color"
"net/http"
"golang.org/x/text/language"
"golang.org/x/text/message"
"gioui.org/gesture"
"gioui.org/io/key"
"gioui.org/layout"
"gioui.org/op/paint"
"gioui.org/widget"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/values"
"github.com/planetdecred/godcr/wallet"
"golang.org/x/exp/shiny/materialdesign/icons"
)
type pageIcons struct {
contentAdd, navigationCheck, navigationMore, actionCheckCircle, actionInfo, navigationArrowBack,
navigationArrowForward, actionCheck, chevronRight, navigationCancel, navMoreIcon,
imageBrightness1, contentClear, dropDownIcon, cached *widget.Icon
overviewIcon, overviewIconInactive, walletIcon, walletIconInactive,
receiveIcon, transactionIcon, transactionIconInactive, sendIcon, moreIcon, moreIconInactive,
pendingIcon, logo, redirectIcon, confirmIcon, newWalletIcon, walletAlertIcon,
importedAccountIcon, accountIcon, editIcon, expandIcon, copyIcon, mixer, mixerSmall,
arrowForwardIcon, transactionFingerPrintIcon, settingsIcon, securityIcon, helpIcon,
aboutIcon, debugIcon, verifyMessageIcon, locationPinIcon, alertGray, arrowDownIcon,
watchOnlyWalletIcon, currencySwapIcon, syncingIcon, proposalIconActive, proposalIconInactive,
restore, documentationIcon, downloadIcon, timerIcon, ticketIcon, ticketIconInactive, stakeyIcon,
list, listGridIcon *widget.Image
ticketPurchasedIcon,
ticketImmatureIcon,
ticketLiveIcon,
ticketVotedIcon,
ticketMissedIcon,
ticketExpiredIcon,
ticketRevokedIcon,
ticketUnminedIcon *widget.Image
}
type navHandler struct {
clickable *widget.Clickable
image *widget.Image
imageInactive *widget.Image
page string
}
type walletAccount struct {
evt *gesture.Click
walletIndex int
accountIndex int
accountName string
totalBalance string
spendable string
number int32
}
type wallectAccountOption struct {
selectSendAccount map[int][]walletAccount
selectReceiveAccount map[int][]walletAccount
selectPurchaseTicketAccount map[int][]walletAccount
}
type DCRUSDTBittrex struct {
LastTradeRate string
}
type walletAccountSelector struct {
title string
walletAccount decredmaterial.Modal
walletsList, accountsList layout.List
isWalletAccountModalOpen bool
isWalletAccountInfo bool
walletAccounts *wallectAccountOption
sendAccountBtn *widget.Clickable
receivingAccountBtn *widget.Clickable
purchaseTicketAccountBtn *widget.Clickable
sendOption string
walletInfoButton decredmaterial.IconButton
selectedSendAccount,
selectedSendWallet,
selectedReceiveAccount,
selectedReceiveWallet,
selectedPurchaseTicketAccount,
selectedPurchaseTicketWallet int
}
type pageCommon struct {
printer *message.Printer
wallet *wallet.Wallet
info *wallet.MultiWalletInfo
selectedWallet *int
selectedAccount *int
theme *decredmaterial.Theme
icons pageIcons
page *string
returnPage *string
amountDCRtoUSD float64
usdExchangeRate float64
usdExchangeSet bool
dcrUsdtBittrex DCRUSDTBittrex
navTab *decredmaterial.Tabs
walletTabs *decredmaterial.Tabs
accountTabs *decredmaterial.Tabs
keyEvents chan *key.Event
toast **toast
states *states
modal *decredmaterial.Modal
modalReceiver chan *modalLoad
modalLoad *modalLoad
modalTemplate *ModalTemplate
appBarNavItems []navHandler
drawerNavItems []navHandler
isNavDrawerMinimized *bool
minimizeNavDrawerButton decredmaterial.IconButton
maximizeNavDrawerButton decredmaterial.IconButton
testButton decredmaterial.Button
selectedUTXO map[int]map[int32]map[string]*wallet.UnspentOutput
subPageBackButton decredmaterial.IconButton
subPageInfoButton decredmaterial.IconButton
changePage func(string)
setReturnPage func(string)
refreshWindow func()
wallAcctSelector *walletAccountSelector
}
type (
C = layout.Context
D = layout.Dimensions
)
func (win *Window) addPages(decredIcons map[string]image.Image) {
ic := pageIcons{
contentAdd: mustIcon(widget.NewIcon(icons.ContentAdd)),
navigationCheck: mustIcon(widget.NewIcon(icons.NavigationCheck)),
navigationMore: mustIcon(widget.NewIcon(icons.NavigationMoreHoriz)),
actionCheckCircle: mustIcon(widget.NewIcon(icons.ActionCheckCircle)),
navigationArrowBack: mustIcon(widget.NewIcon(icons.NavigationArrowBack)),
navigationArrowForward: mustIcon(widget.NewIcon(icons.NavigationArrowForward)),
actionInfo: mustIcon(widget.NewIcon(icons.ActionInfo)),
actionCheck: mustIcon(widget.NewIcon(icons.ActionCheckCircle)),
navigationCancel: mustIcon(widget.NewIcon(icons.NavigationCancel)),
imageBrightness1: mustIcon(widget.NewIcon(icons.ImageBrightness1)),
chevronRight: mustIcon(widget.NewIcon(icons.NavigationChevronRight)),
contentClear: mustIcon(widget.NewIcon(icons.ContentClear)),
navMoreIcon: mustIcon(widget.NewIcon(icons.NavigationMoreHoriz)),
dropDownIcon: mustIcon(widget.NewIcon(icons.NavigationArrowDropDown)),
cached: mustIcon(widget.NewIcon(icons.ActionCached)),
overviewIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["overview"])},
overviewIconInactive: &widget.Image{Src: paint.NewImageOp(decredIcons["overview_inactive"])},
walletIconInactive: &widget.Image{Src: paint.NewImageOp(decredIcons["wallet_inactive"])},
receiveIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["receive"])},
transactionIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["transaction"])},
transactionIconInactive: &widget.Image{Src: paint.NewImageOp(decredIcons["transaction_inactive"])},
sendIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["send"])},
moreIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["more"])},
moreIconInactive: &widget.Image{Src: paint.NewImageOp(decredIcons["more_inactive"])},
logo: &widget.Image{Src: paint.NewImageOp(decredIcons["logo"])},
confirmIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["confirmed"])},
pendingIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["pending"])},
redirectIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["redirect"])},
newWalletIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["addNewWallet"])},
walletAlertIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["walletAlert"])},
accountIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["account"])},
importedAccountIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["imported_account"])},
editIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["editIcon"])},
expandIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["expand_icon"])},
copyIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["copy_icon"])},
mixer: &widget.Image{Src: paint.NewImageOp(decredIcons["mixer"])},
mixerSmall: &widget.Image{Src: paint.NewImageOp(decredIcons["mixer_small"])},
transactionFingerPrintIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["transaction_fingerprint"])},
arrowForwardIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["arrow_forward"])},
settingsIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["settings"])},
securityIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["security"])},
helpIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["help_icon"])},
aboutIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["about_icon"])},
debugIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["debug"])},
verifyMessageIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["verify_message"])},
locationPinIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["location_pin"])},
alertGray: &widget.Image{Src: paint.NewImageOp(decredIcons["alert_gray"])},
arrowDownIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["arrow_down"])},
watchOnlyWalletIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["watch_only_wallet"])},
currencySwapIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["swap"])},
syncingIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["syncing"])},
documentationIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["documentation"])},
proposalIconActive: &widget.Image{Src: paint.NewImageOp(decredIcons["politeiaActive"])},
proposalIconInactive: &widget.Image{Src: paint.NewImageOp(decredIcons["politeiaInactive"])},
restore: &widget.Image{Src: paint.NewImageOp(decredIcons["restore"])},
downloadIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["downloadIcon"])},
timerIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["timerIcon"])},
walletIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["wallet"])},
ticketIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket"])},
ticketIconInactive: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_inactive"])},
stakeyIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["stakey"])},
ticketPurchasedIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_purchased"])},
ticketImmatureIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_immature"])},
ticketUnminedIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_unmined"])},
ticketLiveIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_live"])},
ticketVotedIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_voted"])},
ticketMissedIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_missed"])},
ticketExpiredIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_expired"])},
ticketRevokedIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["ticket_revoked"])},
list: &widget.Image{Src: paint.NewImageOp(decredIcons["list"])},
listGridIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["list_grid"])},
}
win.loadPage(ic)
}
func (win *Window) loadPage(ic pageIcons) {
appBarNavItems := []navHandler{
{
clickable: new(widget.Clickable),
image: ic.sendIcon,
page: PageSend,
},
{
clickable: new(widget.Clickable),
image: ic.receiveIcon,
page: PageReceive,
},
}
drawerNavItems := []navHandler{
{
clickable: new(widget.Clickable),
image: ic.overviewIcon,
imageInactive: ic.overviewIconInactive,
page: PageOverview,
},
{
clickable: new(widget.Clickable),
image: ic.transactionIcon,
imageInactive: ic.transactionIconInactive,
page: PageTransactions,
},
{
clickable: new(widget.Clickable),
image: ic.walletIcon,
imageInactive: ic.walletIconInactive,
page: PageWallet,
},
{
clickable: new(widget.Clickable),
image: ic.proposalIconActive,
imageInactive: ic.proposalIconInactive,
page: PageProposals,
},
{
clickable: new(widget.Clickable),
image: ic.ticketIcon,
imageInactive: ic.ticketIconInactive,
page: PageTickets,
},
{
clickable: new(widget.Clickable),
image: ic.moreIcon,
imageInactive: ic.moreIconInactive,
page: PageMore,
},
}
common := pageCommon{
printer: message.NewPrinter(language.English),
wallet: win.wallet,
info: win.walletInfo,
selectedWallet: &win.selected,
selectedAccount: &win.selectedAccount,
theme: win.theme,
icons: ic,
returnPage: &win.previous,
page: &win.current,
walletTabs: win.walletTabs,
accountTabs: win.accountTabs,
keyEvents: win.keyEvents,
states: &win.states,
appBarNavItems: appBarNavItems,
drawerNavItems: drawerNavItems,
minimizeNavDrawerButton: win.theme.PlainIconButton(new(widget.Clickable), ic.navigationArrowBack),
maximizeNavDrawerButton: win.theme.PlainIconButton(new(widget.Clickable), ic.navigationArrowForward),
selectedUTXO: make(map[int]map[int32]map[string]*wallet.UnspentOutput),
modal: win.theme.Modal(),
modalReceiver: win.modal,
modalLoad: &modalLoad{},
subPageBackButton: win.theme.PlainIconButton(new(widget.Clickable), ic.navigationArrowBack),
subPageInfoButton: win.theme.PlainIconButton(new(widget.Clickable), ic.actionInfo),
changePage: win.changePage,
setReturnPage: win.setReturnPage,
refreshWindow: win.refresh,
toast: &win.toast,
}
common.fetchExchangeValue(&common.dcrUsdtBittrex)
common.wallAcctSelector = &walletAccountSelector{
sendAccountBtn: new(widget.Clickable),
receivingAccountBtn: new(widget.Clickable),
purchaseTicketAccountBtn: new(widget.Clickable),
walletAccount: *common.theme.ModalFloatTitle(),
walletsList: layout.List{Axis: layout.Vertical},
accountsList: layout.List{Axis: layout.Vertical},
walletAccounts: &wallectAccountOption{
selectSendAccount: make(map[int][]walletAccount),
selectReceiveAccount: make(map[int][]walletAccount),
selectPurchaseTicketAccount: make(map[int][]walletAccount),
},
isWalletAccountModalOpen: false,
selectedSendAccount: *common.selectedAccount,
selectedSendWallet: *common.selectedWallet,
selectedReceiveAccount: *common.selectedAccount,
selectedReceiveWallet: *common.selectedWallet,
selectedPurchaseTicketAccount: *common.selectedAccount,
selectedPurchaseTicketWallet: *common.selectedWallet,
}
iconColor := common.theme.Color.Gray3
common.wallAcctSelector.walletInfoButton = common.theme.PlainIconButton(new(widget.Clickable), ic.actionInfo)
common.wallAcctSelector.walletInfoButton.Color = iconColor
common.wallAcctSelector.walletInfoButton.Size = values.MarginPadding15
common.wallAcctSelector.walletInfoButton.Inset = layout.UniformInset(values.MarginPadding0)
common.testButton = win.theme.Button(new(widget.Clickable), "test button")
isNavDrawerMinimized := false
common.isNavDrawerMinimized = &isNavDrawerMinimized
common.minimizeNavDrawerButton.Color, common.maximizeNavDrawerButton.Color = iconColor, iconColor
zeroInset := layout.UniformInset(values.MarginPadding0)
common.subPageBackButton.Color, common.subPageInfoButton.Color = iconColor, iconColor
m25 := values.MarginPadding25
common.subPageBackButton.Size, common.subPageInfoButton.Size = m25, m25
common.subPageBackButton.Inset, common.subPageInfoButton.Inset = zeroInset, zeroInset
common.modalTemplate = win.LoadModalTemplates()
win.pages = make(map[string]layout.Widget)
win.pages[PageWallet] = win.WalletPage(common)
win.pages[PageOverview] = win.OverviewPage(common)
win.pages[PageTransactions] = win.TransactionsPage(common)
win.pages[PageMore] = win.MorePage(common)
win.pages[PageCreateRestore] = win.CreateRestorePage(common)
win.pages[PageReceive] = win.ReceivePage(common)
win.pages[PageSend] = win.SendPage(common)
win.pages[PageTransactionDetails] = win.TransactionDetailsPage(common)
win.pages[PageSignMessage] = win.SignMessagePage(common)
win.pages[PageVerifyMessage] = win.VerifyMessagePage(common)
win.pages[PageSeedBackup] = win.BackupPage(common)
win.pages[PageSettings] = win.SettingsPage(common)
win.pages[PageWalletSettings] = win.WalletSettingsPage(common)
win.pages[PageSecurityTools] = win.SecurityToolsPage(common)
win.pages[PageProposals] = win.ProposalsPage(common)
win.pages[PageProposalDetails] = win.ProposalDetailsPage(common)
win.pages[PageDebug] = win.DebugPage(common)
win.pages[PageLog] = win.LogPage(common)
win.pages[PageAbout] = win.AboutPage(common)
win.pages[PageHelp] = win.HelpPage(common)
win.pages[PageUTXO] = win.UTXOPage(common)
win.pages[PageAccountDetails] = win.AcctDetailsPage(common)
win.pages[PagePrivacy] = win.PrivacyPage(common)
win.pages[PageTickets] = win.TicketPage(common)
win.pages[ValidateAddress] = win.ValidateAddressPage(common)
win.pages[PageTicketsList] = win.TicketPageList(common)
}
func (page *pageCommon) fetchExchangeValue(target interface{}) error {
url := "https://api.bittrex.com/v3/markets/DCR-USDT/ticker"
res, err := http.Get(url)
if err != nil {
return err
}
defer res.Body.Close()
err = json.NewDecoder(res.Body).Decode(target)
if err != nil {
log.Error(err)
}
return nil
}
func (page pageCommon) refreshPage() {
page.refreshWindow()
}
func (page pageCommon) notify(text string, success bool) {
*page.toast = &toast{
text: text,
success: success,
}
}
func (page pageCommon) closeModal() {
go func() {
page.modalReceiver <- &modalLoad{
title: "",
confirm: nil,
cancel: nil,
}
}()
}
func (page pageCommon) Layout(gtx layout.Context, body layout.Widget) layout.Dimensions {
page.handler()
return layout.Stack{}.Layout(gtx,
layout.Expanded(func(gtx C) D {
// fill the entire window with a color if a user has no wallet created
if *page.page == PageCreateRestore {
return decredmaterial.Fill(gtx, page.theme.Color.Surface)
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(page.layoutTopBar),
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
card := page.theme.Card()
card.Radius = decredmaterial.CornerRadius{}
return card.Layout(gtx, page.layoutNavDrawer)
}),
layout.Rigid(func(gtx C) D {
return body(gtx)
}),
)
}),
)
}),
layout.Stacked(func(gtx C) D {
// stack the page content on the entire window if a user has no wallet
if *page.page == PageCreateRestore {
return body(gtx)
}
return layout.Dimensions{}
}),
layout.Stacked(func(gtx C) D {
// global modal. Stack modal on all pages and contents
outer:
for {
select {
case load := <-page.modalReceiver:
page.modalLoad.template = load.template
page.modalLoad.title = load.title
page.modalLoad.confirm = load.confirm
page.modalLoad.confirmText = load.confirmText
page.modalLoad.cancel = load.cancel
page.modalLoad.cancelText = load.cancelText
page.modalLoad.isReset = false
default:
break outer
}
}
if page.modalLoad.cancel != nil {
return page.modal.Layout(gtx, page.modalTemplate.Layout(page.theme, page.modalLoad),
900)
}
return layout.Dimensions{}
}),
layout.Stacked(func(gtx C) D {
// global toasts. Stack toast on all pages and contents
if *page.toast == nil {
return layout.Dimensions{}
}
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Center.Layout(gtx, func(gtx C) D {
return layout.Inset{Top: values.MarginPadding65}.Layout(gtx, func(gtx C) D {
return displayToast(page.theme, gtx, *page.toast)
})
})
}),
layout.Stacked(func(gtx C) D {
if page.wallAcctSelector.isWalletAccountModalOpen {
return page.walletAccountModalLayout(gtx)
}
return layout.Dimensions{}
}),
)
}
// Container is simply a wrapper for the Inset type. Its purpose is to differentiate the use of an inset as a padding or
// margin, making it easier to visualize the structure of a layout when reading UI code.
type Container struct {
padding layout.Inset
}
func (c Container) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
return c.padding.Layout(gtx, w)
}
func (page pageCommon) UniformPadding(gtx layout.Context, body layout.Widget) layout.Dimensions {
return layout.UniformInset(values.MarginPadding24).Layout(gtx, body)
}
type SubPage struct {
title string
subTitle string
walletName string
back func()
body layout.Widget
infoTemplate string
extraItem *widget.Clickable
extra layout.Widget
extraText string
handleExtra func()
}
func (page pageCommon) SubPageLayout(gtx layout.Context, sp SubPage) layout.Dimensions {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Inset{Bottom: values.MarginPadding15}.Layout(gtx, func(gtx C) D {
return page.subpageHeader(gtx, sp)
})
}),
layout.Rigid(sp.body),
)
}
func (page pageCommon) subpageHeader(gtx layout.Context, sp SubPage) layout.Dimensions {
page.subpageEventHandler(sp)
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Inset{Right: values.MarginPadding20}.Layout(gtx, func(gtx C) D {
return page.subPageBackButton.Layout(gtx)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
if sp.subTitle == "" {
return page.theme.H6(sp.title).Layout(gtx)
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return page.theme.H6(sp.title).Layout(gtx)
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return page.theme.Body1(sp.subTitle).Layout(gtx)
}),
)
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
if sp.walletName != "" {
return layout.Inset{Left: values.MarginPadding5, Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
return decredmaterial.Card{
Color: page.theme.Color.Surface,
}.Layout(gtx, func(gtx C) D {
return layout.UniformInset(values.MarginPadding2).Layout(gtx, func(gtx C) D {
walletText := page.theme.Caption(sp.walletName)
walletText.Color = page.theme.Color.Gray
return walletText.Layout(gtx)
})
})
})
}
return layout.Dimensions{}
}),
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
return layout.E.Layout(gtx, func(gtx C) D {
if sp.infoTemplate != "" {
return page.subPageInfoButton.Layout(gtx)
} else if sp.extraItem != nil {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
if sp.extraText != "" {
return layout.Inset{Right: values.MarginPadding10, Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
text := page.theme.Caption(sp.extraText)
text.Color = page.theme.Color.DeepBlue
return text.Layout(gtx)
})
}
return layout.Dimensions{}
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return decredmaterial.Clickable(gtx, sp.extraItem, sp.extra)
}),
)
}
return layout.Dimensions{}
})
}),
)
}
func (page pageCommon) SubpageSplitLayout(gtx layout.Context, sp SubPage) layout.Dimensions {
card := page.theme.Card()
card.Color = color.NRGBA{}
return card.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D { return page.subpageHeader(gtx, sp) }),
layout.Rigid(sp.body),
)
})
}
func (page pageCommon) subpageEventHandler(sp SubPage) {
if page.subPageInfoButton.Button.Clicked() {
go func() {
page.modalReceiver <- &modalLoad{
template: sp.infoTemplate,
title: sp.title,
cancel: page.closeModal,
cancelText: "Got it",
}
}()
}
if page.subPageBackButton.Button.Clicked() {
sp.back()
}
if sp.extraItem != nil && sp.extraItem.Clicked() {
sp.handleExtra()
}
}