Skip to content

Commit

Permalink
review changes
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 96276b2 commit 4f4d3ba
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 297 deletions.
153 changes: 46 additions & 107 deletions ui/cryptomaterial/dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,7 @@ func (d *DropDown) layoutActiveIcon(gtx C, index int) D {
return icon.Layout(gtx, values.MarginPadding20)
}

func (d *DropDown) layoutCollapsedItem(gtx C, itemIndex int) D {
if len(d.items) == 0 {
if d.extraDisplay != nil {
return d.extraDisplay(gtx)
}
return D{}
}

item := d.items[itemIndex]
radius := Radius(8)
clickable := d.clickable
clickable.Hoverable = d.MakeSelectedItemHoverableAfterCollapse

func (d *DropDown) itemLayout(gtx C, index int, clickable *Clickable, item *DropDownItem, radius int, bodyLayout *LinearLayout) D {
padding := values.MarginPadding10
if item.Icon != nil {
padding = values.MarginPadding8
Expand All @@ -226,7 +214,7 @@ func (d *DropDown) layoutCollapsedItem(gtx C, itemIndex int) D {
Height: WrapContent,
Clickable: clickable,
Padding: layout.UniformInset(padding),
Border: Border{Radius: radius},
Border: Border{Radius: Radius(radius)},
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if item.Icon == nil {
Expand All @@ -240,14 +228,7 @@ func (d *DropDown) layoutCollapsedItem(gtx C, itemIndex int) D {
return item.DisplayFn(gtx)
}

ll := LinearLayout{
Width: MatchParent,
Height: WrapContent,
Padding: layout.Inset{Right: values.MarginPadding5},
Direction: d.SelectedItemDirectionAfterCollapse,
}

return ll.Layout2(gtx, func(gtx C) D {
return bodyLayout.Layout2(gtx, func(gtx C) D {
lbl := d.theme.Body2(item.Text)
if !d.expanded && len(item.Text) > maxDropdownItemTextLen {
lbl.Text = item.Text[:maxDropdownItemTextLen-3 /* subtract space for the ellipsis */] + "..."
Expand All @@ -257,60 +238,42 @@ func (d *DropDown) layoutCollapsedItem(gtx C, itemIndex int) D {
})
}),
layout.Rigid(func(gtx C) D {
return d.layoutActiveIcon(gtx, itemIndex)
return d.layoutActiveIcon(gtx, index)
}),
)
}

func (d *DropDown) layoutExpandedItem(gtx C, itemIndex int) D {
item := d.items[itemIndex]
radius := Radius(0)
clickable := item.clickable

padding := values.MarginPadding10
if item.Icon != nil {
padding = values.MarginPadding8
func (d *DropDown) selectedItemLayout(gtx C) D {
if len(d.items) == 0 {
if d.extraDisplay != nil {
return d.extraDisplay(gtx)
}
return D{}
}

return LinearLayout{
item := d.items[d.selectedIndex]
clickable := d.clickable
clickable.Hoverable = d.MakeSelectedItemHoverableAfterCollapse
bodyLayout := LinearLayout{
Width: MatchParent,
Height: WrapContent,
Clickable: clickable,
Padding: layout.UniformInset(padding),
Border: Border{Radius: radius},
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if item.Icon == nil {
return D{}
}
Padding: layout.Inset{Right: values.MarginPadding5},
Direction: d.SelectedItemDirectionAfterCollapse,
}

return item.Icon.Layout24dp(gtx)
}),
layout.Flexed(1, func(gtx C) D {
if item.DisplayFn != nil {
return item.DisplayFn(gtx)
}
return d.itemLayout(gtx, d.selectedIndex, clickable, &item, 8, &bodyLayout)
}

ll := LinearLayout{
Width: MatchParent,
Height: WrapContent,
Padding: layout.Inset{Right: values.MarginPadding5},
Direction: layout.W,
}
func (d *DropDown) layoutExpandedItem(gtx C, itemIndex int) D {
item := d.items[itemIndex]
body := LinearLayout{
Width: MatchParent,
Height: WrapContent,
Padding: layout.Inset{Right: values.MarginPadding5},
Direction: layout.W,
}

return ll.Layout2(gtx, func(gtx C) D {
lbl := d.theme.Body2(item.Text)
if !d.expanded && len(item.Text) > maxDropdownItemTextLen {
lbl.Text = item.Text[:maxDropdownItemTextLen-3 /* subtract space for the ellipsis */] + "..."
}
lbl.Font.Weight = d.FontWeight
return lbl.Layout(gtx)
})
}),
layout.Rigid(func(gtx C) D {
return d.layoutActiveIcon(gtx, itemIndex)
}),
)
return d.itemLayout(gtx, itemIndex, item.clickable, &item, 8, &body)
}

// defaultDropdownWidth returns the default width for a dropdown depending on
Expand All @@ -330,19 +293,16 @@ func (d *DropDown) Layout(gtx C) D {
d.handleEvents()

if d.StackBelowCollapsedLayout {
expanded := d.expanded
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx,
layout.Expanded(func(gtx C) D {
d.expanded = false // enforce a collapsed layout display before creating the layout Dimensions and undo later.
display := d.collapsedLayout(gtx)
d.expanded = expanded
return display
}),
layout.Stacked(func(gtx C) D {
if !d.expanded {
return D{}
}
layoutContents := []layout.StackChild{layout.Expanded(func(gtx C) D {
expanded := d.expanded
d.expanded = false // enforce a collapsed layout display before creating the layout Dimensions and undo later.
display := d.collapsedLayout(gtx)
d.expanded = expanded
return display
})}

if d.expanded {
layoutContents = append(layoutContents, layout.Expanded(func(gtx layout.Context) layout.Dimensions {
// Adding d.ExpandedLayoutInset.Top accounts for the the extra
// shift in vertical space set by d.ExpandedLayoutInset.Top to
// ensure the expanded view has enough space for its elements.
Expand All @@ -353,8 +313,10 @@ func (d *DropDown) Layout(gtx C) D {

gtx.Constraints.Max.Y = gtx.Dp(maxY)
return d.expandedLayout(gtx)
}),
)
}))
}

return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx, layoutContents...)
}

if d.GroupPosition == DropdownBasePos && d.isDropdownGroupCollapsed(d.group) {
Expand All @@ -366,35 +328,18 @@ func (d *DropDown) Layout(gtx C) D {
gtx.Constraints.Max.Y = gtx.Dp(maxY)
if d.expanded {
return d.backdrop.Layout(gtx, func(gtx C) D {
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx,
layout.Stacked(func(gtx C) D {
return d.expandedLayout(gtx)
}),
)
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx, layout.Stacked(d.expandedLayout))
})
}

return d.backdrop.Layout(gtx, func(gtx C) D {
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx,
layout.Stacked(func(gtx C) D {
return d.collapsedLayout(gtx)
}),
)
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx, layout.Stacked(d.collapsedLayout))
})

} else if d.expanded {
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx,
layout.Stacked(func(gtx C) D {
return d.expandedLayout(gtx)
}),
)
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx, layout.Stacked(d.expandedLayout))
}

return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx,
layout.Stacked(func(gtx C) D {
return d.collapsedLayout(gtx)
}),
)
return layout.Stack{Alignment: d.expandedViewAlignment}.Layout(gtx, layout.Stacked(d.collapsedLayout))
}

// expandedLayout computes dropdown layout when dropdown is opened.
Expand Down Expand Up @@ -424,13 +369,7 @@ func (d *DropDown) expandedLayout(gtx C) D {
// collapsedLayout computes dropdown layout when dropdown is closed.
func (d *DropDown) collapsedLayout(gtx C) D {
return d.collapsedLayoutInset.Layout(gtx, func(gtx C) D {
return d.drawLayout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return d.layoutCollapsedItem(gtx, d.selectedIndex)
}),
)
})
return d.drawLayout(gtx, d.selectedItemLayout)
})
}

Expand Down
20 changes: 6 additions & 14 deletions ui/page/dcrdex/dex_onboarding_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ func (pg *DEXOnboarding) onBoardingStep(gtx C, step onboardingStep, stepDesc str
layout.Rigid(func(gtx C) D {
inset := layout.Inset{Top: u10, Bottom: u10}
if !activeStep {
return inset.Layout(gtx, func(gtx C) D {
return semiBoldLabelGrey3(pg.Theme, gtx, stepDesc)
})
return inset.Layout(gtx, semiBoldLabelGrey3(pg.Theme, stepDesc).Layout)
}

lb := pg.semiBoldLabel(stepDesc)
Expand Down Expand Up @@ -711,9 +709,7 @@ func (pg *DEXOnboarding) stepWaitForBondConfirmation(gtx C) D {
layout.Flexed(0.33, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{Bottom: 5}.Layout(gtx, func(gtx C) D {
return semiBoldLabelGrey3(pg.Theme, gtx, values.String(values.StrNewTier))
})
return layout.Inset{Bottom: 5}.Layout(gtx, semiBoldLabelGrey3(pg.Theme, values.String(values.StrNewTier)).Layout)
}),
layout.Rigid(func(gtx C) D {
return pg.Theme.Body1(fmt.Sprintf("%d", pg.newTier)).Layout(gtx)
Expand All @@ -723,9 +719,7 @@ func (pg *DEXOnboarding) stepWaitForBondConfirmation(gtx C) D {
layout.Flexed(0.33, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{Bottom: 5}.Layout(gtx, func(gtx C) D {
return semiBoldLabelGrey3(pg.Theme, gtx, values.String(values.StrBondStrength))
})
return layout.Inset{Bottom: 5}.Layout(gtx, semiBoldLabelGrey3(pg.Theme, values.String(values.StrBondStrength)).Layout)
}),
layout.Rigid(func(gtx C) D {
return pg.Theme.Body1(fmt.Sprintf("%d", pg.newTier /* TODO: Use real value */)).Layout(gtx)
Expand All @@ -735,9 +729,7 @@ func (pg *DEXOnboarding) stepWaitForBondConfirmation(gtx C) D {
layout.Flexed(0.33, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{Bottom: 5}.Layout(gtx, func(gtx C) D {
return semiBoldLabelGrey3(pg.Theme, gtx, values.String(values.StrTotalCost))
})
return layout.Inset{Bottom: 5}.Layout(gtx, semiBoldLabelGrey3(pg.Theme, values.String(values.StrTotalCost)).Layout)
}),
layout.Rigid(func(gtx C) D {
return pg.bondAmountInfoDisplay(gtx)
Expand Down Expand Up @@ -943,11 +935,11 @@ func (pg *DEXOnboarding) validateBondStrength() bool {
return ok
}

func semiBoldLabelGrey3(th *cryptomaterial.Theme, gtx C, text string) D {
func semiBoldLabelGrey3(th *cryptomaterial.Theme, text string) cryptomaterial.Label {
lb := th.Label(values.TextSize16, text)
lb.Color = th.Color.GrayText3
lb.Font.Weight = font.SemiBold
return lb.Layout(gtx)
return lb
}

func (pg *DEXOnboarding) passwordsMatch(editors ...*widget.Editor) bool {
Expand Down
Loading

0 comments on commit 4f4d3ba

Please sign in to comment.