New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement dark mode #401
Implement dark mode #401
Changes from 6 commits
64e7f3e
bcb6181
252ce9e
87fd4f7
4ad65f8
e418236
3bf0ffc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,23 @@ const ( | |
|
||
// layoutBalance aligns the main and sub DCR balances horizontally, putting the sub | ||
// balance at the baseline of the row. | ||
func (page pageCommon) layoutBalance(gtx layout.Context, amount string) layout.Dimensions { | ||
func (page pageCommon) layoutBalance(gtx layout.Context, amount string, isSwitchColor bool) layout.Dimensions { | ||
// todo: make "DCR" symbols small when there are no decimals in the balance | ||
mainText, subText := breakBalance(page.printer, amount) | ||
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Baseline}.Layout(gtx, | ||
layout.Rigid(func(gtx C) D { | ||
return page.theme.Label(values.TextSize20, mainText).Layout(gtx) | ||
label := page.theme.Label(values.TextSize20, mainText) | ||
if isSwitchColor { | ||
label.Color = page.theme.Color.DeepBlue | ||
} | ||
return label.Layout(gtx) | ||
}), | ||
layout.Rigid(func(gtx C) D { | ||
return page.theme.Label(values.TextSize14, subText).Layout(gtx) | ||
label := page.theme.Label(values.TextSize14, subText) | ||
if isSwitchColor { | ||
label.Color = page.theme.Color.DeepBlue | ||
} | ||
return label.Layout(gtx) | ||
}), | ||
) | ||
} | ||
|
@@ -60,7 +68,7 @@ func (page pageCommon) layoutUSDBalance(gtx layout.Context) layout.Dimensions { | |
Top: values.MarginPadding3, | ||
Left: values.MarginPadding8, | ||
} | ||
border := widget.Border{Color: page.theme.Color.LightGray, CornerRadius: unit.Dp(8), Width: unit.Dp(0.5)} | ||
border := widget.Border{Color: page.theme.Color.Gray, CornerRadius: unit.Dp(8), Width: unit.Dp(0.5)} | ||
return inset.Layout(gtx, func(gtx C) D { | ||
padding := layout.Inset{ | ||
Top: values.MarginPadding3, | ||
|
@@ -71,7 +79,8 @@ func (page pageCommon) layoutUSDBalance(gtx layout.Context) layout.Dimensions { | |
return border.Layout(gtx, func(gtx C) D { | ||
return padding.Layout(gtx, func(gtx C) D { | ||
amountDCRtoUSDString := formatUSDBalance(page.printer, page.amountDCRtoUSD) | ||
return page.theme.Label(values.TextSize14, amountDCRtoUSDString).Layout(gtx) | ||
return page.theme.Body2(amountDCRtoUSDString).Layout(gtx) | ||
//return page.theme.LabelColor(values.TextSize14, amountDCRtoUSDString, page.theme.Color.DeepBlue).Layout(gtx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove redundant comments |
||
}) | ||
}) | ||
}) | ||
|
@@ -108,7 +117,7 @@ func (page pageCommon) layoutTopBar(gtx layout.Context) layout.Dimensions { | |
}), | ||
layout.Rigid(func(gtx C) D { | ||
return layout.Center.Layout(gtx, func(gtx C) D { | ||
return page.layoutBalance(gtx, page.info.TotalBalance) | ||
return page.layoutBalance(gtx, page.info.TotalBalance, true) | ||
}) | ||
}), | ||
layout.Rigid(func(gtx C) D { | ||
|
@@ -178,7 +187,7 @@ func (page pageCommon) layoutNavDrawer(gtx layout.Context) layout.Dimensions { | |
return list.Layout(gtx, len(page.drawerNavItems), func(gtx C, i int) D { | ||
background := page.theme.Color.Surface | ||
if page.drawerNavItems[i].page == *page.page { | ||
background = page.theme.Color.LightGray | ||
background = page.theme.Color.ActiveGray | ||
} | ||
txt := page.theme.Label(values.TextSize16, page.drawerNavItems[i].page) | ||
return decredmaterial.Clickable(gtx, page.drawerNavItems[i].clickable, func(gtx C) D { | ||
|
@@ -221,7 +230,7 @@ func (page pageCommon) layoutNavDrawer(gtx layout.Context) layout.Dimensions { | |
Left: leftInset, | ||
Top: values.MarginPadding4, | ||
}.Layout(gtx, func(gtx C) D { | ||
textColor := page.theme.Color.Gray3 | ||
textColor := page.theme.Color.Gray4 | ||
if page.drawerNavItems[i].page == *page.page { | ||
textColor = page.theme.Color.DeepBlue | ||
} | ||
|
@@ -313,7 +322,7 @@ func transactionRow(gtx layout.Context, common pageCommon, row TransactionRow) l | |
return layout.Inset{Left: values.MarginPadding16}.Layout(gtx, func(gtx C) D { | ||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx, | ||
layout.Rigid(func(gtx C) D { | ||
return common.layoutBalance(gtx, row.transaction.Balance) | ||
return common.layoutBalance(gtx, row.transaction.Balance, true) | ||
}), | ||
layout.Rigid(func(gtx C) D { | ||
if row.showBadge { | ||
|
@@ -334,7 +343,11 @@ func transactionRow(gtx layout.Context, common pageCommon, row TransactionRow) l | |
s = row.transaction.Status | ||
} | ||
status := common.theme.Body1(s) | ||
status.Color = common.theme.Color.Gray | ||
if row.transaction.Status != "confirmed" { | ||
status.Color = common.theme.Color.Gray5 | ||
} else { | ||
status.Color = common.theme.Color.Gray4 | ||
} | ||
status.Alignment = text.Middle | ||
return status.Layout(gtx) | ||
}) | ||
|
@@ -661,7 +674,7 @@ func (page *pageCommon) walletAccountLayout(gtx layout.Context, wallAcct walletA | |
acct := page.theme.Label(values.TextSize18, wallAcct.accountName) | ||
acct.Color = page.theme.Color.Text | ||
return endToEndRow(gtx, acct.Layout, func(gtx C) D { | ||
return page.layoutBalance(gtx, wallAcct.totalBalance) | ||
return page.layoutBalance(gtx, wallAcct.totalBalance, true) | ||
}) | ||
}), | ||
layout.Rigid(func(gtx C) D { | ||
|
@@ -879,7 +892,7 @@ func ticketCard(gtx layout.Context, c pageCommon, t *wallet.Ticket) layout.Dimen | |
return layout.Inset{ | ||
Top: values.MarginPadding16, | ||
}.Layout(gtx, func(gtx C) D { | ||
return c.layoutBalance(gtx, t.Amount) | ||
return c.layoutBalance(gtx, t.Amount, true) | ||
}) | ||
}), | ||
layout.Rigid(func(gtx C) D { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ type overviewPage struct { | |
} | ||
|
||
func (win *Window) OverviewPage(c pageCommon) layout.Widget { | ||
|
||
pg := overviewPage{ | ||
theme: c.theme, | ||
tab: c.navTab, | ||
|
@@ -162,7 +163,7 @@ func (win *Window) OverviewPage(c pageCommon) layout.Widget { | |
pg.cachedIcon = c.icons.cached | ||
|
||
return func(gtx C) D { | ||
pg.Handler(gtx, c) | ||
pg.Handler(gtx, c, win) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need to pass the window struct to the handler method. It seems you're trying to call the reload method from the handler after toggling the dark mode option. Is there a reason you need to re-initialize the icons and pages after toggling the dark mode option? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, i need re-initialize pages after toggling the dark mode option. |
||
return pg.Layout(gtx, c) | ||
} | ||
} | ||
|
@@ -639,7 +640,16 @@ func (pg *overviewPage) walletSyncBox(gtx layout.Context, inset layout.Inset, de | |
}) | ||
} | ||
|
||
func (pg *overviewPage) Handler(eq event.Queue, c pageCommon) { | ||
func (pg *overviewPage) Handler(eq event.Queue, c pageCommon, win *Window) { | ||
|
||
if win.wallet != nil { | ||
isDarkModeOn := win.wallet.ReadBoolConfigValueForKey("isDarkModeOn") | ||
if isDarkModeOn != win.theme.DarkMode { | ||
win.theme.SwitchDarkMode(isDarkModeOn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this method called in the overview and settings page. Shouldn't it be called just once from the settings page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I called it in the settings page to handle the button click event dark mode. In the overview page because it is the first page loaded when app startup, i can read config from the wallet in this page and switch to the dark mode. |
||
win.reloadPage(c) | ||
} | ||
} | ||
|
||
if pg.walletInfo.Synced { | ||
pg.sync.Text = pg.text.disconnect | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,11 @@ func (win *Window) addPages(decredIcons map[string]image.Image) { | |
listGridIcon: &widget.Image{Src: paint.NewImageOp(decredIcons["list_grid"])}, | ||
} | ||
|
||
win.loadPage(ic) | ||
} | ||
|
||
func (win *Window) loadPage(ic pageIcons) { | ||
|
||
appBarNavItems := []navHandler{ | ||
{ | ||
clickable: new(widget.Clickable), | ||
|
@@ -377,6 +382,10 @@ func (win *Window) addPages(decredIcons map[string]image.Image) { | |
win.pages[PageTicketsList] = win.TicketPageList(common) | ||
} | ||
|
||
func (win *Window) reloadPage(common pageCommon) { | ||
win.loadPage(common.icons) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a redundant wrapper for the loadPage method. |
||
|
||
func (page *pageCommon) fetchExchangeValue(target interface{}) error { | ||
url := "https://api.bittrex.com/v3/markets/DCR-USDT/ticker" | ||
res, err := http.Get(url) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the colour for the text being done specifically here, shouldn't it be affected like other text colours in the app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the text in here alway display black color independent dark or light mode