Skip to content

Commit

Permalink
review changes and lint error fix
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Nov 20, 2023
1 parent 5ecb1df commit 96276b2
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
26 changes: 19 additions & 7 deletions ui/cryptomaterial/dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,23 @@ type DropDownItem struct {
DisplayFn func(gtx C) D
}

// DropDown returns a dropdown component. {groupPosition} parameter signifies
// the position of the dropdown in a dropdown group on the UI, the first
// dropdown should be assigned pos 0, next 1..etc. incorrectly assigned Dropdown
// pos will result in inconsistent dropdown backdrop.
func (t *Theme) DropDown(items []DropDownItem, group uint, groupPosition uint, dropPos int, reversePos bool) *DropDown {
// DropdownWithCustomPos returns a dropdown component. {groupPosition} parameter
// signifies the position of the dropdown in a dropdown group on the UI, the
// first dropdown should be assigned pos 0, next 1..etc. incorrectly assigned
// Dropdown pos will result in inconsistent dropdown backdrop. {dropdownInset}
// parameter is the left inset for the dropdown if {reversePos} is false, else
// it'll become the right inset for the dropdown.
func (t *Theme) DropdownWithCustomPos(items []DropDownItem, group uint, groupPosition uint, dropdownInset int, reversePos bool) *DropDown {
return t.dropdown(items, group, groupPosition, dropdownInset, reversePos)
}

// DropDown is like DropdownWithCustomPos but uses default values for
// groupPosition, and dropdownInset parameters.
func (t *Theme) DropDown(items []DropDownItem, group uint, reversePos bool) *DropDown {
return t.dropdown(items, group, 0, 0, reversePos)
}

func (t *Theme) dropdown(items []DropDownItem, group uint, groupPosition uint, dropdownInset int, reversePos bool) *DropDown {
d := &DropDown{
theme: t,
expanded: false,
Expand All @@ -95,11 +107,11 @@ func (t *Theme) DropDown(items []DropDownItem, group uint, groupPosition uint, d

d.revs = reversePos
d.expandedViewAlignment = layout.NW
d.ExpandedLayoutInset = layout.Inset{Left: unit.Dp(dropPos)}
d.ExpandedLayoutInset = layout.Inset{Left: unit.Dp(dropdownInset)}
if d.revs {
d.expandedViewAlignment = layout.NE
d.ExpandedLayoutInset.Left = values.MarginPadding10
d.ExpandedLayoutInset.Right = unit.Dp(dropPos)
d.ExpandedLayoutInset.Right = unit.Dp(dropdownInset)
}
d.collapsedLayoutInset = d.ExpandedLayoutInset

Expand Down
2 changes: 1 addition & 1 deletion ui/page/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ func InputsNotEmpty(editors ...*widget.Editor) bool {

// IconButton create the display for an icon button. The default icon and text
// color is Theme.Color.Primary.
func IconButton(gtx C, icon *widget.Icon, txt string, inset layout.Inset, th *cryptomaterial.Theme, clickable *cryptomaterial.Clickable) func(gtx C) D {
func IconButton(icon *widget.Icon, txt string, inset layout.Inset, th *cryptomaterial.Theme, clickable *cryptomaterial.Clickable) func(gtx C) D {
return func(gtx C) D {
return inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
color := th.Color.Primary
Expand Down
2 changes: 1 addition & 1 deletion ui/page/dcrdex/dcrdex_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewDEXPage(l *load.Load) *DEXPage {
MasterPage: app.NewMasterPage(DCRDEXID),
openTradeMainPage: l.Theme.NewClickable(false),
}

// TODO: Set dp.inited
dp.inited = true
return dp
Expand Down
4 changes: 2 additions & 2 deletions ui/page/dcrdex/dex_onboarding_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewDEXOnboarding(l *load.Load) *DEXOnboarding {
currentStep: onboardingSetPassword,
passwordEditor: newPasswordEditor(th, values.String(values.StrNewPassword)),
confirmPasswordEditor: newPasswordEditor(th, values.String(values.StrConfirmPassword)),
serverDropDown: th.DropDown(knownDEXServers[l.WL.AssetsManager.NetType()], values.DEXServerDropdownGroup, 0, 0, false),
serverDropDown: th.DropDown(knownDEXServers[l.WL.AssetsManager.NetType()], values.DEXServerDropdownGroup, false),
addServerBtn: th.NewClickable(false),
serverURLEditor: newTextEditor(th, values.String(values.StrServerURL), values.String(values.StrInputURL), false),
serverCertEditor: newTextEditor(th, values.String(values.StrCertificateOPtional), values.String(values.StrInputCertificate), true),
Expand Down Expand Up @@ -364,7 +364,7 @@ func (pg *DEXOnboarding) stepChooseServer(gtx C) D {
return layout.Inset{Top: u20}.Layout(gtx, l.Layout)
}),
layout.Rigid(pg.serverDropDown.Layout),
layout.Rigid(components.IconButton(gtx, pg.Theme.Icons.ContentAdd, values.String(values.StrAddServer),
layout.Rigid(components.IconButton(pg.Theme.Icons.ContentAdd, values.String(values.StrAddServer),
layout.Inset{Top: u16}, pg.Theme, pg.addServerBtn),
),
layout.Rigid(func(gtx C) D {
Expand Down
8 changes: 4 additions & 4 deletions ui/page/dcrdex/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewDEXMarketPage(l *load.Load) *DEXMarketPage {
createOrderBtn: th.Button(values.String(values.StrBuy)), // TODO: toggle
buyOrder: true,
immediateOrder: th.CheckBox(new(widget.Bool), values.String(values.StrImmediate)),
orderTypesDropdown: th.DropDown(orderTypes, values.DEXOrderTypes, 0, 0, true),
orderTypesDropdown: th.DropDown(orderTypes, values.DEXOrderTypes, true),
immediateMoreInfo: th.NewClickable(false),
addServerBtn: th.NewClickable(false),
seeFullOrderBookBtn: th.Button(values.String(values.StrSeeMore)),
Expand Down Expand Up @@ -157,7 +157,7 @@ func (pg *DEXMarketPage) OnNavigatedTo() {
})
}

pg.serverSelector = pg.Theme.DropDown(servers, values.DEXServerDropdownGroup, 0, 0, false)
pg.serverSelector = pg.Theme.DropDown(servers, values.DEXServerDropdownGroup, false)
pg.serverSelector.SetExtraDisplay(pg.addServerBtnDisplay)
pg.marketSelector = pg.Theme.DropDown([]cryptomaterial.DropDownItem{
{
Expand All @@ -172,7 +172,7 @@ func (pg *DEXMarketPage) OnNavigatedTo() {
Text: "LTC/BTC",
DisplayFn: pg.marketDropdownListItem(libutils.LTCWalletAsset, libutils.BTCWalletAsset),
},
}, values.DEXCurrencyPairGroup, 0, 0, false)
}, values.DEXCurrencyPairGroup, false)

pg.serverSelector.Width, pg.marketSelector.Width = u300, u300
pg.serverSelector.StackBelowCollapsedLayout, pg.marketSelector.StackBelowCollapsedLayout = true, true
Expand Down Expand Up @@ -285,7 +285,7 @@ func (pg *DEXMarketPage) Layout(gtx C) D {
func (pg DEXMarketPage) addServerBtnDisplay(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(pg.Theme.Separator().Layout),
layout.Rigid(components.IconButton(gtx, pg.Theme.Icons.ContentAdd, values.String(values.StrAddServer),
layout.Rigid(components.IconButton(pg.Theme.Icons.ContentAdd, values.String(values.StrAddServer),
layout.Inset{Top: u10, Bottom: u5, Left: values.MarginPadding8}, pg.Theme, pg.addServerBtn,
)),
)
Expand Down
2 changes: 1 addition & 1 deletion ui/page/exchange/order_history_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewOrderHistoryPage(l *load.Load) *OrderHistoryPage {
pg.ordersList = pg.Theme.NewClickableList(layout.Vertical)
pg.ordersList.IsShadowEnabled = true

pg.statusDropdown = l.Theme.DropDown([]cryptomaterial.DropDownItem{
pg.statusDropdown = l.Theme.DropdownWithCustomPos([]cryptomaterial.DropDownItem{
{Text: api.OrderStatusWaitingForDeposit.String()},
{Text: api.OrderStatusDepositReceived.String()},
{Text: api.OrderStatusNew.String()},
Expand Down
2 changes: 1 addition & 1 deletion ui/page/governance/consensus_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewConsensusPage(l *load.Load) *ConsensusPage {
pg.infoButton.Size = values.MarginPadding20
pg.navigateToSettingsBtn = pg.Theme.Button(values.StringF(values.StrEnableAPI, values.String(values.StrGovernance)))

pg.statusDropDown = l.Theme.DropDown([]cryptomaterial.DropDownItem{
pg.statusDropDown = l.Theme.DropdownWithCustomPos([]cryptomaterial.DropDownItem{
{Text: values.String(values.StrAll)},
{Text: values.String(values.StrUpcoming)},
{Text: values.String(values.StrInProgress)},
Expand Down
2 changes: 1 addition & 1 deletion ui/page/governance/proposals_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewProposalsPage(l *load.Load) *ProposalsPage {
_, pg.infoButton = components.SubpageHeaderButtons(l)
pg.infoButton.Size = values.MarginPadding20

pg.statusDropDown = l.Theme.DropDown([]cryptomaterial.DropDownItem{
pg.statusDropDown = l.Theme.DropdownWithCustomPos([]cryptomaterial.DropDownItem{
{Text: values.String(values.StrAll)},
{Text: values.String(values.StrUnderReview)},
{Text: values.String(values.StrApproved)},
Expand Down
4 changes: 2 additions & 2 deletions ui/page/transaction/transactions_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (pg *TransactionsPage) refreshAvailableTxType() {
items = append(items, item)
}

pg.txTypeDropDown = pg.Theme.DropDown(items, values.TxDropdownGroup, 2, 0, true)
pg.txTypeDropDown = pg.Theme.DropdownWithCustomPos(items, values.TxDropdownGroup, 2, 0, true)

go func() {
countfn := func(fType int32) int {
Expand All @@ -177,7 +177,7 @@ func (pg *TransactionsPage) refreshAvailableTxType() {
}
items = append(items, item)
}
pg.txTypeDropDown = pg.Theme.DropDown(items, values.TxDropdownGroup, 2, 0, true)
pg.txTypeDropDown = pg.Theme.DropdownWithCustomPos(items, values.TxDropdownGroup, 2, 0, true)
pg.ParentWindow().Reload()
}()
}
Expand Down

0 comments on commit 96276b2

Please sign in to comment.