Skip to content

Commit

Permalink
- link send page to utxo page
Browse files Browse the repository at this point in the history
- change utxo to send package
- move mustIcon function to util component
- add menu item for send page
- fix crash in uxto page
  • Loading branch information
JustinBeBoy committed Sep 5, 2021
1 parent 5603d40 commit 7f85194
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 56 deletions.
12 changes: 11 additions & 1 deletion ui/page/components/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package components

import "context"
import (
"context"
"gioui.org/widget"
)

// done returns whether the context's Done channel was closed due to
// cancellation or exceeded deadline.
Expand All @@ -12,3 +15,10 @@ func ContextDone(ctx context.Context) bool {
return false
}
}

func MustIcon(ic *widget.Icon, err error) *widget.Icon {
if err != nil {
panic(err)
}
return ic
}
2 changes: 1 addition & 1 deletion ui/page/create_restore_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func NewCreateRestorePage(l *load.Load) *CreateRestore {

pg.restoreWalletBtn = l.Theme.Button(new(widget.Clickable), "Restore")

pg.closePageBtn = l.Theme.IconButton(new(widget.Clickable), mustIcon(widget.NewIcon(icons.NavigationClose)))
pg.closePageBtn = l.Theme.IconButton(new(widget.Clickable), components.MustIcon(widget.NewIcon(icons.NavigationClose)))
pg.closePageBtn.Background = color.NRGBA{}
pg.closePageBtn.Color = l.Theme.Color.Hint

Expand Down
2 changes: 1 addition & 1 deletion ui/page/privacy_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (pg *PrivacyPage) showModalSetupMixerAcct() {
accounts, _ := pg.wallet.GetAccountsRaw()
for _, acct := range accounts.Acc {
if acct.Name == "mixed" || acct.Name == "unmixed" {
alert := mustIcon(widget.NewIcon(icons.AlertError))
alert := components.MustIcon(widget.NewIcon(icons.AlertError))
alert.Color = pg.Theme.Color.DeepBlue

info := modal.NewInfoModal(pg.Load).
Expand Down
2 changes: 1 addition & 1 deletion ui/page/receive_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewReceivePage(l *load.Load) *ReceivePage {
pageContainer: layout.List{
Axis: layout.Vertical,
},
info: l.Theme.IconButton(new(widget.Clickable), mustIcon(widget.NewIcon(icons.ActionInfo))),
info: l.Theme.IconButton(new(widget.Clickable), components.MustIcon(widget.NewIcon(icons.ActionInfo))),
copy: l.Theme.Button(new(widget.Clickable), "Copy"),
more: l.Theme.PlainIconButton(new(widget.Clickable), l.Icons.NavMoreIcon),
newAddr: l.Theme.Button(new(widget.Clickable), "Generate new address"),
Expand Down
74 changes: 62 additions & 12 deletions ui/page/send/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package send

import (
"fmt"

"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/page/components"
"github.com/planetdecred/godcr/ui/values"
Expand All @@ -22,7 +23,6 @@ func (pg *Page) initLayoutWidgets() {
Alignment: layout.Middle,
}

pg.clearAllBtn = pg.Theme.Button(new(widget.Clickable), "Clear all fields")
pg.txFeeCollapsible = pg.Theme.Collapsible()

pg.nextButton = pg.Theme.Button(new(widget.Clickable), "Next")
Expand All @@ -43,10 +43,6 @@ func (pg *Page) initLayoutWidgets() {
Right: values.MarginPadding8,
Bottom: values.MarginPadding5,
Left: values.MarginPadding8}

pg.clearAllBtn.Background = pg.Theme.Color.Surface
pg.clearAllBtn.Color = pg.Theme.Color.Text
pg.clearAllBtn.Inset = layout.UniformInset(values.MarginPadding15)
}

func (pg *Page) topNav(gtx layout.Context) layout.Dimensions {
Expand All @@ -71,12 +67,7 @@ func (pg *Page) topNav(gtx layout.Context) layout.Dimensions {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if pg.moreOptionIsOpen {
macro := op.Record(gtx.Ops)
layout.Inset{Top: values.MarginPadding25, Left: values.MarginPaddingMinus90}.Layout(gtx, func(gtx C) D {
border := widget.Border{Color: pg.Theme.Color.Background, CornerRadius: values.MarginPadding5, Width: values.MarginPadding1}
return border.Layout(gtx, pg.clearAllBtn.Layout)
})
op.Defer(gtx.Ops, macro.Stop())
pg.layoutOptionsMenu(gtx)
}
return layout.Dimensions{}
}),
Expand All @@ -90,6 +81,59 @@ func (pg *Page) topNav(gtx layout.Context) layout.Dimensions {
)
}

func (pg *Page) getMoreItem() []moreItem {
return []moreItem{
{
text: values.String(values.StrAdvancedMode),
button: new(widget.Clickable),
id: UTXOPageID,
},
{
text: values.String(values.StrClearFeilds),
button: new(widget.Clickable),
action: func() {
pg.moreOptionIsOpen = false
pg.sendDestination.clearAddressInput()
pg.amount.clearAmount()
},
},
}
}

func (pg *Page) layoutOptionsMenu(gtx layout.Context) {
var leftInset float32
leftInset = -120

inset := layout.Inset{
Top: unit.Dp(30),
Left: unit.Dp(leftInset),
}

m := op.Record(gtx.Ops)
inset.Layout(gtx, func(gtx C) D {
width := unit.Value{U: unit.UnitDp, V: 150}
gtx.Constraints.Max.X = gtx.Px(width)
return pg.shadowBox.Layout(gtx, func(gtx C) D {
return pg.optionsMenuCard.Layout(gtx, func(gtx C) D {
return (&layout.List{Axis: layout.Vertical}).Layout(gtx, len(pg.moreItems), func(gtx C, i int) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return material.Clickable(gtx, pg.moreItems[i].button, func(gtx C) D {
m10 := values.MarginPadding10
return layout.Inset{Top: m10, Bottom: m10, Left: m10, Right: m10}.Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return pg.Theme.Body1(pg.moreItems[i].text).Layout(gtx)
})
})
}),
)
})
})
})
})
op.Defer(gtx.Ops, m.Stop())
}

func (pg *Page) Layout(gtx layout.Context) layout.Dimensions {
pageContent := []func(gtx C) D{
func(gtx C) D {
Expand Down Expand Up @@ -136,6 +180,12 @@ func (pg *Page) Layout(gtx layout.Context) layout.Dimensions {
})
})
}),
layout.Expanded(func(gtx C) D {
if pg.moreOptionIsOpen {
return pg.backdrop.Layout(gtx)
}
return D{}
}),
)

return dims
Expand Down
43 changes: 38 additions & 5 deletions ui/page/send/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package send

import (
"fmt"
"gioui.org/widget"
"strconv"
"strings"

Expand All @@ -19,6 +20,14 @@ const (
PageID = "Send"
)

type moreItem struct {
text string
id string
button *widget.Clickable
action func()
separate bool
}

type Page struct {
*load.Load
pageContainer layout.List
Expand All @@ -32,7 +41,6 @@ type Page struct {
moreOption decredmaterial.IconButton
retryExchange decredmaterial.Button
nextButton decredmaterial.Button
clearAllBtn decredmaterial.Button

txFeeCollapsible *decredmaterial.Collapsible

Expand All @@ -42,6 +50,10 @@ type Page struct {
exchangeError string

*authoredTxData
shadowBox *decredmaterial.Shadow
optionsMenuCard decredmaterial.Card
moreItems []moreItem
backdrop *widget.Clickable
}

type authoredTxData struct {
Expand Down Expand Up @@ -69,6 +81,8 @@ func NewSendPage(l *load.Load) *Page {
exchangeRate: -1,

authoredTxData: &authoredTxData{},
shadowBox: l.Theme.Shadow(),
backdrop: new(widget.Clickable),
}

// Source account picker
Expand Down Expand Up @@ -115,6 +129,11 @@ func NewSendPage(l *load.Load) *Page {

pg.initLayoutWidgets()

pg.optionsMenuCard = decredmaterial.Card{Color: pg.Theme.Color.Surface}
pg.optionsMenuCard.Radius = decredmaterial.Radius(5)

pg.moreItems = pg.getMoreItem()

return pg
}

Expand Down Expand Up @@ -318,14 +337,28 @@ func (pg *Page) Handle() {
}
}

for pg.clearAllBtn.Clicked() {
for _, menu := range pg.moreItems {
if menu.button.Clicked() {
switch menu.id {
case UTXOPageID:
pg.ChangeFragment(NewUTXOPage(pg.Load))
default:
menu.action()
}
}
}

for pg.backdrop.Clicked() {
pg.moreOptionIsOpen = false
}

pg.sendDestination.clearAddressInput()
}

pg.amount.clearAmount()
func (pg *Page) mustIcon(ic *widget.Icon, err error) *widget.Icon {
if err != nil {
panic(err)
}

return ic
}

func (pg *Page) OnClose() {
Expand Down
Loading

0 comments on commit 7f85194

Please sign in to comment.