Skip to content

Commit

Permalink
add proposal details page
Browse files Browse the repository at this point in the history
  • Loading branch information
ugwueze-dev committed Feb 28, 2021
1 parent 91bfcb5 commit e01d0bc
Show file tree
Hide file tree
Showing 11 changed files with 1,165 additions and 21 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ go 1.13

require (
gioui.org v0.0.0-20210124160655-f88a8216e9d7
github.com/ararog/timeago v0.0.0-20160328174124-e9969cf18b8d
github.com/decred/dcrd/chaincfg v1.5.2
github.com/decred/dcrd/chaincfg/chainhash v1.0.2
github.com/decred/dcrd/dcrutil v1.4.0
github.com/decred/dcrd/dcrutil/v2 v2.0.1
github.com/decred/dcrd/dcrutil/v3 v3.0.0
github.com/decred/slog v1.1.0
github.com/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28
github.com/gomarkdown/markdown v0.0.0-20210208175418-bda154fe17d8
github.com/jessevdk/go-flags v1.4.1-0.20200711081900-c17162fe8fd7
github.com/jrick/logrotate v1.0.0
github.com/onsi/ginkgo v1.14.0
Expand All @@ -19,7 +21,6 @@ require (
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3
golang.org/x/image v0.0.0-20200618115811-c13761719519
github.com/ararog/timeago v0.0.0-20160328174124-e9969cf18b8d
)

// TODO: Remove and use an actual release of dcrlibwallet
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28 h1:M2Zt3G2w6Q57GZndOYk42p7RvMeO8izO8yKTfIxGqxA=
github.com/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28/go.mod h1:ElSskYZe3oM8kThaHGJ+kiN2yyUMVXMZ7WxF9QqLDS8=
Expand Down Expand Up @@ -359,6 +360,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomarkdown/markdown v0.0.0-20210208175418-bda154fe17d8 h1:nWU6p08f1VgIalT6iZyqXi4o5cZsz4X6qa87nusfcsc=
github.com/gomarkdown/markdown v0.0.0-20210208175418-bda154fe17d8/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/certificate-transparency-go v1.0.21/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -442,16 +445,19 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/otiai10/copy v1.0.1/go.mod h1:8bMCJrAqOtN/d9oyh5HR7HhLQMvcGMpGdwRDYsfOCHc=
Expand Down Expand Up @@ -525,6 +531,7 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180808211826-de0752318171/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -672,11 +679,13 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
213 changes: 213 additions & 0 deletions ui/decredmaterial/grid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package decredmaterial

import (
"image"

"gioui.org/layout"
"gioui.org/op"
)

// inf is an infinite axis constraint.
const inf = 1e6

// GridElement lays out the ith element of a Grid.
type GridElement func(gtx layout.Context, i int) layout.Dimensions

// Grid lays out at most Num elements along the main axis.
// The number of cross axis elements depend on the total number of elements.
type Grid struct {
Num int
Axis layout.Axis
Alignment layout.Alignment
list layout.List
}

// GridWrap lays out as many elements as possible along the main axis
// before wrapping to the cross axis.
type GridWrap struct {
Axis layout.Axis
Alignment layout.Alignment
}

type wrapData struct {
dims layout.Dimensions
call op.CallOp
}

func (g GridWrap) Layout(gtx layout.Context, num int, el GridElement) layout.Dimensions {
defer op.Save(gtx.Ops).Load()
csMax := gtx.Constraints.Max
var mainSize, crossSize, mainPos, crossPos, base int
gtx.Constraints.Min = image.Point{}
mainCs := axisMain(g.Axis, csMax)
crossCs := axisCross(g.Axis, gtx.Constraints.Max)

var els []wrapData
for i := 0; i < num; i++ {
macro := op.Record(gtx.Ops)
dims, okMain, okCross := g.place(gtx, i, el)
call := macro.Stop()
if !okMain && !okCross {
break
}
main := axisMain(g.Axis, dims.Size)
cross := axisCross(g.Axis, dims.Size)
if okMain {
els = append(els, wrapData{dims, call})

mainCs := axisMain(g.Axis, gtx.Constraints.Max)
gtx.Constraints.Max = axisPoint(g.Axis, mainCs-main, crossCs)

mainPos += main
crossPos = max(crossPos, cross)
base = max(base, dims.Baseline)
continue
}
// okCross
mainSize = max(mainSize, mainPos)
crossSize += crossPos
g.placeAll(gtx.Ops, els, crossPos, base)
els = append(els[:0], wrapData{dims, call})

gtx.Constraints.Max = axisPoint(g.Axis, mainCs-main, crossCs-crossPos)
mainPos = main
crossPos = cross
base = dims.Baseline
}
mainSize = max(mainSize, mainPos)
crossSize += crossPos
g.placeAll(gtx.Ops, els, crossPos, base)
sz := axisPoint(g.Axis, mainSize, crossSize)
return layout.Dimensions{Size: sz}
}

func (g GridWrap) place(gtx layout.Context, i int, el GridElement) (dims layout.Dimensions, okMain, okCross bool) {
cs := gtx.Constraints
if g.Axis == layout.Horizontal {
gtx.Constraints.Max.X = inf
} else {
gtx.Constraints.Max.Y = inf
}
dims = el(gtx, i)
okMain = dims.Size.X <= cs.Max.X
okCross = dims.Size.Y <= cs.Max.Y
if g.Axis == layout.Vertical {
okMain, okCross = okCross, okMain
}
return
}

func (g GridWrap) placeAll(ops *op.Ops, els []wrapData, crossMax, baseMax int) {
var mainPos int
var pt image.Point
for i, el := range els {
cross := axisCross(g.Axis, el.dims.Size)
switch g.Alignment {
case layout.Start:
cross = 0
case layout.End:
cross = crossMax - cross
case layout.Middle:
cross = (crossMax - cross) / 2
case layout.Baseline:
if g.Axis == layout.Horizontal {
cross = baseMax - el.dims.Baseline
} else {
cross = 0
}
}
if cross == 0 {
el.call.Add(ops)
} else {
pt = axisPoint(g.Axis, 0, cross)
op.Offset(layout.FPt(pt)).Add(ops)
el.call.Add(ops)
op.Offset(layout.FPt(pt.Mul(-1))).Add(ops)
}
if i == len(els)-1 {
pt = axisPoint(g.Axis, -mainPos, crossMax)
} else {
main := axisMain(g.Axis, el.dims.Size)
pt = axisPoint(g.Axis, main, 0)
mainPos += main
}
op.Offset(layout.FPt(pt)).Add(ops)
}
}

func (g *Grid) Layout(gtx layout.Context, num int, el GridElement) layout.Dimensions {
if g.Num == 0 {
return layout.Dimensions{Size: gtx.Constraints.Min}
}
if g.Axis == g.list.Axis {
if g.Axis == layout.Horizontal {
g.list.Axis = layout.Vertical
} else {
g.list.Axis = layout.Horizontal
}
g.list.Alignment = g.Alignment
}
csMax := gtx.Constraints.Max
return g.list.Layout(gtx, (num+g.Num-1)/g.Num, func(gtx layout.Context, idx int) layout.Dimensions {
defer op.Save(gtx.Ops).Load()
if g.Axis == layout.Horizontal {
gtx.Constraints.Max.Y = inf
} else {
gtx.Constraints.Max.X = inf
}
gtx.Constraints.Min = image.Point{}
var mainMax, crossMax int
left := axisMain(g.Axis, csMax)
i := idx * g.Num
n := min(num, i+g.Num)
for ; i < n; i++ {
dims := el(gtx, i)
main := axisMain(g.Axis, dims.Size)
crossMax = max(crossMax, axisCross(g.Axis, dims.Size))
left -= main
if left <= 0 {
mainMax = axisMain(g.Axis, csMax)
break
}
pt := axisPoint(g.Axis, main, 0)
op.Offset(layout.FPt(pt)).Add(gtx.Ops)
mainMax += main
}
return layout.Dimensions{Size: axisPoint(g.Axis, mainMax, crossMax)}
})
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func axisPoint(a layout.Axis, main, cross int) image.Point {
if a == layout.Horizontal {
return image.Point{main, cross}
}
return image.Point{cross, main}
}

func axisMain(a layout.Axis, sz image.Point) int {
if a == layout.Horizontal {
return sz.X
}
return sz.Y
}

func axisCross(a layout.Axis, sz image.Point) int {
if a == layout.Horizontal {
return sz.Y
}
return sz.X
}
4 changes: 2 additions & 2 deletions ui/decredmaterial/tooltip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"image"
"image/color"

"gioui.org/layout"
"gioui.org/widget"
"gioui.org/f32"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"gioui.org/widget"

"github.com/planetdecred/godcr/ui/values"
)
Expand Down
6 changes: 4 additions & 2 deletions ui/decredmaterial/votebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type VoteBar struct {
passPercentage float32
yesColor color.NRGBA
noColor color.NRGBA
bgColor color.NRGBA

yesLabel Label
noLabel Label
Expand Down Expand Up @@ -50,6 +51,7 @@ func (t *Theme) VoteBar(infoIcon, legendIcon *widget.Icon) VoteBar {
quorumTooltip: t.Tooltip("", Left),
infoIcon: infoIcon,
legendIcon: legendIcon,
bgColor: t.Color.Gray,
}
}

Expand Down Expand Up @@ -128,14 +130,14 @@ func (v *VoteBar) LayoutWithLegend(gtx C) D {
leftPos := (v.passPercentage / 100) * float32(gtx.Constraints.Max.X)
return layout.Inset{
Left: unit.Dp(leftPos),
Top: values.MarginPadding20,
Top: values.MarginPadding20,
}.Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = 3
gtx.Constraints.Min.Y = 28

v.passTooltip.SetText(fmt.Sprintf("%d %% Yes votes required for approval", int(v.passPercentage)))
return v.passTooltip.Layout(gtx, func(gtx C) D {
return fill(gtx, v.yesColor)
return fill(gtx, v.bgColor)
})
})
}),
Expand Down
9 changes: 8 additions & 1 deletion ui/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ type pageCommon struct {
subPageBackButton decredmaterial.IconButton
subPageInfoButton decredmaterial.IconButton

changePage func(string)
changePage func(string)
refreshWindow func()
}

type (
Expand Down Expand Up @@ -245,6 +246,7 @@ func (win *Window) addPages(decredIcons map[string]image.Image) {
subPageBackButton: win.theme.PlainIconButton(new(widget.Clickable), ic.navigationArrowBack),
subPageInfoButton: win.theme.PlainIconButton(new(widget.Clickable), ic.actionInfo),
changePage: win.changePage,
refreshWindow: win.refreshWindow,
}

common.testButton = win.theme.Button(new(widget.Clickable), "test button")
Expand Down Expand Up @@ -276,6 +278,7 @@ func (win *Window) addPages(decredIcons map[string]image.Image) {
win.pages[PageWalletSettings] = win.WalletSettingsPage(common)
win.pages[PageSecurityTools] = win.SecurityToolsPage(common)
win.pages[PageProposals] = win.ProposalsPage(common)
win.pages[PageProposalDetails] = win.ProposalDetailsPage(common)
win.pages[PageDebug] = win.DebugPage(common)
win.pages[PageAbout] = win.AboutPage(common)
win.pages[PageHelp] = win.HelpPage(common)
Expand All @@ -289,6 +292,10 @@ func (page pageCommon) ChangePage(pg string) {
page.changePage(pg)
}

func (page pageCommon) refresh() {
page.refreshWindow()
}

func (page pageCommon) Notify(text string, success bool) {
go func() {
page.toast <- &toast{
Expand Down

0 comments on commit e01d0bc

Please sign in to comment.