Skip to content

Commit

Permalink
rename layoutWithLagend(), rename shaper()
Browse files Browse the repository at this point in the history
* move gotoURL() to util.go
  • Loading branch information
Sirmorrison committed Apr 19, 2021
1 parent ebb7070 commit 81b5e9b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
11 changes: 7 additions & 4 deletions ui/decredmaterial/votebar.go
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/planetdecred/godcr/ui/values"
)

// VoteBar widget implements voting stat for proposals.
// VoteBar shows the range/percentage of the yes votes and no votes against the total required.
type VoteBar struct {
yesVotes float32
noVotes float32
Expand Down Expand Up @@ -100,7 +102,8 @@ func (v *VoteBar) Layout(gtx C) D {
yesWidth := (progressBarWidth / 100) * yesVotes
noWidth := (progressBarWidth / 100) * noVotes

shader := func(width float32, color color.NRGBA, layer int) layout.Dimensions {
// progressScale represent the different progress bar layers
progressScale := func(width float32, color color.NRGBA, layer int) layout.Dimensions {
maxHeight := unit.Dp(8)
rW, rN = 0, 0
if layer == 2 {
Expand Down Expand Up @@ -135,21 +138,21 @@ func (v *VoteBar) Layout(gtx C) D {

return layout.Stack{Alignment: layout.W}.Layout(gtx,
layout.Stacked(func(gtx layout.Context) layout.Dimensions {
return shader(progressBarWidth, v.bgColor, 1)
return progressScale(progressBarWidth, v.bgColor, 1)
}),
layout.Stacked(func(gtx layout.Context) layout.Dimensions {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if yesWidth == 0 {
return D{}
}
return shader(yesWidth, v.yesColor, 2)
return progressScale(yesWidth, v.yesColor, 2)
}),
layout.Rigid(func(gtx C) D {
if noWidth == 0 {
return D{}
}
return shader(noWidth, v.noColor, 3)
return progressScale(noWidth, v.noColor, 3)
}),
)
}),
Expand Down
26 changes: 3 additions & 23 deletions ui/proposal_details_page.go
Expand Up @@ -3,8 +3,6 @@ package ui
import (
"encoding/base64"
"fmt"
"os/exec"
"runtime"
"strings"

"gioui.org/layout"
Expand Down Expand Up @@ -79,37 +77,19 @@ func (pg *proposalDetails) handle() {
for token := range pg.proposalItems {
for location, clickable := range pg.proposalItems[token].clickables {
if clickable.Clicked() {
pg.goToURL(location)
goToURL(location)
}
}
}

for pg.viewInPoliteiaBtn.Clicked() {
proposal := *pg.selectedProposal
pg.goToURL("https://proposals.decred.org/proposals/" + proposal.Token)
goToURL("https://proposals.decred.org/proposals/" + proposal.Token)
}

for pg.viewInGithubBtn.Clicked() {
proposal := *pg.selectedProposal
pg.goToURL("https://github.com/decred-proposals/mainnet/tree/master/" + proposal.Token)
}
}

func (pg *proposalDetails) goToURL(url string) {
var err error

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Error(err)
goToURL("https://github.com/decred-proposals/mainnet/tree/master/" + proposal.Token)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/proposals_page.go
Expand Up @@ -454,7 +454,7 @@ func (pg *proposalsPage) layoutProposalVoteBar(gtx C, proposalItem proposalItem)
passPercentage := float32(proposalItem.proposal.PassPercentage)
eligibleTickets := float32(proposalItem.proposal.EligibleTickets)

return proposalItem.voteBar.SetParams(yes, no, eligibleTickets, quorumPercent, passPercentage).LayoutWithLegend(gtx)
return proposalItem.voteBar.SetParams(yes, no, eligibleTickets, quorumPercent, passPercentage).Layout(gtx)
}

func (pg *proposalsPage) layoutProposalsList(gtx C) D {
Expand Down
20 changes: 20 additions & 0 deletions ui/util.go
Expand Up @@ -5,6 +5,8 @@ package ui

import (
"fmt"
"os/exec"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -94,3 +96,21 @@ func breakBalance(p *message.Printer, balance string) (b1, b2 string) {
b2 = " " + b2
return
}

func goToURL(url string) {
var err error

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Error(err)
}
}

0 comments on commit 81b5e9b

Please sign in to comment.