Skip to content

Commit

Permalink
Add menu item and link send page to utxo page (#614)
Browse files Browse the repository at this point in the history
- link send page to utxo page
- move mustIcon function to util component
- add menu item for send page
- move mustIcon function to decredmaterial
refactor code in utxo page and send page
- fix crash when utxo page is opened
- clean up code

Co-authored-by: sirmorrison <edonomorrison@gmail.com>
  • Loading branch information
JustinBeBoy and Sirmorrison authored Sep 9, 2021
1 parent 8aecf43 commit fc82427
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 161 deletions.
6 changes: 3 additions & 3 deletions ui/decredmaterial/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (t *Theme) Editor(editor *widget.Editor, hint string) Editor {

showHidePassword: IconButton{
material.IconButtonStyle{
Icon: mustIcon(widget.NewIcon(icons.ActionVisibilityOff)),
Icon: MustIcon(widget.NewIcon(icons.ActionVisibilityOff)),
Size: values.MarginPadding24,
Background: color.NRGBA{},
Color: t.Color.Gray,
Expand Down Expand Up @@ -218,9 +218,9 @@ func (e Editor) editor(gtx layout.Context) layout.Dimensions {
Left: e.m5,
}
return inset.Layout(gtx, func(gtx C) D {
icon := mustIcon(widget.NewIcon(icons.ActionVisibilityOff))
icon := MustIcon(widget.NewIcon(icons.ActionVisibilityOff))
if e.Editor.Mask == '*' {
icon = mustIcon(widget.NewIcon(icons.ActionVisibility))
icon = MustIcon(widget.NewIcon(icons.ActionVisibility))
}
e.showHidePassword.Icon = icon
return e.showHidePassword.Layout(gtx)
Expand Down
4 changes: 2 additions & 2 deletions ui/decredmaterial/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ func NewTabs(th *Theme) *Tabs {
// scrollButton lays out the right and left scroll buttons of the tab when Position is Horizontal.
func (t *Tabs) scrollButton(right bool, button *widget.Clickable) layout.FlexChild {
show := false
icon := mustIcon(widget.NewIcon(icons.NavigationChevronLeft))
icon := MustIcon(widget.NewIcon(icons.NavigationChevronLeft))
if right && t.list.Position.BeforeEnd {
show = true
icon = mustIcon(widget.NewIcon(icons.NavigationChevronRight))
icon = MustIcon(widget.NewIcon(icons.NavigationChevronRight))
}

if !right && t.list.Position.Offset > 0 {
Expand Down
20 changes: 10 additions & 10 deletions ui/decredmaterial/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ func NewTheme(fontCollection []text.FontFace, decredIcons map[string]image.Image

t.setColorMode(isDarkModeOn)

t.checkBoxCheckedIcon = mustIcon(widget.NewIcon(icons.ToggleCheckBox))
t.checkBoxUncheckedIcon = mustIcon(widget.NewIcon(icons.ToggleCheckBoxOutlineBlank))
t.radioCheckedIcon = mustIcon(widget.NewIcon(icons.ToggleRadioButtonChecked))
t.radioUncheckedIcon = mustIcon(widget.NewIcon(icons.ToggleRadioButtonUnchecked))
t.chevronUpIcon = mustIcon(widget.NewIcon(icons.NavigationExpandLess))
t.chevronDownIcon = mustIcon(widget.NewIcon(icons.NavigationExpandMore))
t.navMoreIcon = mustIcon(widget.NewIcon(icons.NavigationMoreHoriz))
t.navigationCheckIcon = mustIcon(widget.NewIcon(icons.NavigationCheck))
t.dropDownIcon = mustIcon(widget.NewIcon(icons.NavigationArrowDropDown))
t.checkBoxCheckedIcon = MustIcon(widget.NewIcon(icons.ToggleCheckBox))
t.checkBoxUncheckedIcon = MustIcon(widget.NewIcon(icons.ToggleCheckBoxOutlineBlank))
t.radioCheckedIcon = MustIcon(widget.NewIcon(icons.ToggleRadioButtonChecked))
t.radioUncheckedIcon = MustIcon(widget.NewIcon(icons.ToggleRadioButtonUnchecked))
t.chevronUpIcon = MustIcon(widget.NewIcon(icons.NavigationExpandLess))
t.chevronDownIcon = MustIcon(widget.NewIcon(icons.NavigationExpandMore))
t.navMoreIcon = MustIcon(widget.NewIcon(icons.NavigationMoreHoriz))
t.navigationCheckIcon = MustIcon(widget.NewIcon(icons.NavigationCheck))
t.dropDownIcon = MustIcon(widget.NewIcon(icons.NavigationArrowDropDown))

t.expandIcon = &widget.Image{Src: paint.NewImageOp(decredIcons["expand_icon"])}
t.collapseIcon = &widget.Image{Src: paint.NewImageOp(decredIcons["collapse_icon"])}
Expand Down Expand Up @@ -223,7 +223,7 @@ func (t *Theme) ImageIcon(gtx layout.Context, icon image.Image, size int) layout
return i.Layout(gtx)
}

func mustIcon(ic *widget.Icon, err error) *widget.Icon {
func MustIcon(ic *widget.Icon, err error) *widget.Icon {
if err != nil {
panic(err)
}
Expand Down
32 changes: 16 additions & 16 deletions ui/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ type Load struct {

func NewLoad(th *decredmaterial.Theme, decredIcons map[string]image.Image) *Load {
ic := Icons{
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)),
ContentRemove: mustIcon(widget.NewIcon(icons.ContentRemove)),
ContentAdd: decredmaterial.MustIcon(widget.NewIcon(icons.ContentAdd)),
NavigationCheck: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationCheck)),
NavigationMore: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationMoreHoriz)),
ActionCheckCircle: decredmaterial.MustIcon(widget.NewIcon(icons.ActionCheckCircle)),
NavigationArrowBack: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationArrowBack)),
NavigationArrowForward: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationArrowForward)),
ActionInfo: decredmaterial.MustIcon(widget.NewIcon(icons.ActionInfo)),
ActionCheck: decredmaterial.MustIcon(widget.NewIcon(icons.ActionCheckCircle)),
NavigationCancel: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationCancel)),
ImageBrightness1: decredmaterial.MustIcon(widget.NewIcon(icons.ImageBrightness1)),
ChevronRight: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationChevronRight)),
ContentClear: decredmaterial.MustIcon(widget.NewIcon(icons.ContentClear)),
NavMoreIcon: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationMoreHoriz)),
DropDownIcon: decredmaterial.MustIcon(widget.NewIcon(icons.NavigationArrowDropDown)),
Cached: decredmaterial.MustIcon(widget.NewIcon(icons.ActionCached)),
ContentRemove: decredmaterial.MustIcon(widget.NewIcon(icons.ContentRemove)),

OverviewIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["overview"])},
OverviewIconInactive: &widget.Image{Src: paint.NewImageOp(decredIcons["overview_inactive"])},
Expand Down
11 changes: 0 additions & 11 deletions ui/load/utils.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
package load

import (
"gioui.org/widget"
)

const Uint32Size = 32 << (^uint32(0) >> 32 & 1) // 32 or 64
const MaxInt32 = 1<<(Uint32Size-1) - 1

func mustIcon(ic *widget.Icon, err error) *widget.Icon {
if err != nil {
panic(err)
}
return ic
}
4 changes: 2 additions & 2 deletions ui/modal/info_modal_layouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func privacyInfo(th *decredmaterial.Theme) []layout.Widget {
func(gtx C) D {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Rigid(func(gtx C) D {
ic := mustIcon(widget.NewIcon(icons.ImageLens))
ic := decredmaterial.MustIcon(widget.NewIcon(icons.ImageLens))
ic.Color = th.Color.Gray
return ic.Layout(gtx, values.MarginPadding8)
}),
Expand All @@ -70,7 +70,7 @@ func privacyInfo(th *decredmaterial.Theme) []layout.Widget {
func(gtx C) D {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Rigid(func(gtx C) D {
ic := mustIcon(widget.NewIcon(icons.ImageLens))
ic := decredmaterial.MustIcon(widget.NewIcon(icons.ImageLens))
ic.Color = th.Color.Gray
return ic.Layout(gtx, values.MarginPadding8)
}),
Expand Down
7 changes: 0 additions & 7 deletions ui/modal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,3 @@ func computePasswordStrength(pb *decredmaterial.ProgressBarStyle, th *decredmate
pb.Progress = float32(strength * 100)
pb.Color = th.Color.Success
}

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), decredmaterial.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 := decredmaterial.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), decredmaterial.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
72 changes: 61 additions & 11 deletions ui/page/send/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"gioui.org/layout"
"gioui.org/op"
"gioui.org/widget"

"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,9 @@ 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)
pg.optionsMenuCard = decredmaterial.Card{Color: pg.Theme.Color.Surface}
pg.optionsMenuCard.Radius = decredmaterial.Radius(5)
pg.moreItems = pg.getMoreItem()
}

func (pg *Page) topNav(gtx layout.Context) layout.Dimensions {
Expand All @@ -71,12 +70,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 +84,56 @@ func (pg *Page) topNav(gtx layout.Context) layout.Dimensions {
)
}

func (pg *Page) getMoreItem() []moreItem {
return []moreItem{
{
text: "Advanced mode",
button: new(widget.Clickable),
id: UTXOPageID,
action: func() {
pg.ChangeFragment(NewUTXOPage(pg.Load, pg.sourceAccountSelector.SelectedAccount()))
},
},
{
text: "Clear all fields",
button: new(widget.Clickable),
action: func() {
pg.resetFields()
pg.moreOptionIsOpen = false
},
},
}
}

func (pg *Page) layoutOptionsMenu(gtx layout.Context) {
inset := layout.Inset{
Top: values.MarginPadding30,
Left: values.MarginPaddingMinus100,
}

m := op.Record(gtx.Ops)
inset.Layout(gtx, func(gtx C) D {
gtx.Constraints.Max.X = gtx.Px(values.MarginPadding130)
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 decredmaterial.Clickable(gtx, pg.moreItems[i].button, func(gtx C) D {
return layout.UniformInset(values.MarginPadding10).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
26 changes: 21 additions & 5 deletions ui/page/send/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"gioui.org/layout"
"gioui.org/widget"

"github.com/decred/dcrd/dcrutil/v3"
"github.com/planetdecred/dcrlibwallet"
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,9 +41,12 @@ type Page struct {
moreOption decredmaterial.IconButton
retryExchange decredmaterial.Button
nextButton decredmaterial.Button
clearAllBtn decredmaterial.Button

txFeeCollapsible *decredmaterial.Collapsible
shadowBox *decredmaterial.Shadow
optionsMenuCard decredmaterial.Card
moreItems []moreItem
backdrop *widget.Clickable

moreOptionIsOpen bool

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 @@ -318,12 +332,14 @@ func (pg *Page) Handle() {
}
}

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

pg.sendDestination.clearAddressInput()

pg.amount.clearAmount()
for _, menu := range pg.moreItems {
if menu.button.Clicked() {
menu.action()
}
}

}
Expand Down
Loading

0 comments on commit fc82427

Please sign in to comment.