/
about.go
166 lines (140 loc) · 4.91 KB
/
about.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package about
import (
"gioui.org/io/clipboard"
"gioui.org/layout"
"gioui.org/widget"
"gioui.org/widget/material"
"gioui.org/x/component"
alo "github.com/annomel/go-getit/applayout"
"github.com/annomel/go-getit/icon"
page "github.com/annomel/go-getit/pages"
)
type (
C = layout.Context
D = layout.Dimensions
)
// Page holds the state for a page demonstrating the features of
// the AppBar component.
type Page struct {
eliasCopyButton, chrisCopyButtonGH, chrisCopyButtonLP widget.Clickable
grabV3 widget.Clickable
grabV3Field component.TextField
humanize widget.Clickable
humanizeField component.TextField
widget.List
*page.Router
}
// New constructs a Page with the provided router.
func New(router *page.Router) *Page {
p := &Page{
Router: router,
}
p.grabV3Field.ReadOnly = true
p.grabV3Field.SetText(grabV3)
p.humanizeField.ReadOnly = true
p.humanizeField.SetText(humanize)
return p
}
var _ page.Page = &Page{}
func (p *Page) Actions() []component.AppBarAction {
return []component.AppBarAction{}
}
func (p *Page) Overflow() []component.OverflowAction {
return []component.OverflowAction{}
}
func (p *Page) NavItem() component.NavItem {
return component.NavItem{
Name: "About",
Icon: icon.OtherIcon,
}
}
const (
sponsorEliasURL = "https://github.com/sponsors/eliasnaur"
sponsorChrisURLGitHub = "https://github.com/sponsors/whereswaldon"
sponsorChrisURLLiberapay = "https://liberapay.com/whereswaldon/"
grabV3 = "https://github.com/cavaliergopher/grab"
humanize = "https://github.com/dustin/go-humanize"
)
func (p *Page) Layout(gtx C, th *material.Theme) D {
p.List.Axis = layout.Vertical
return material.List(th, &p.List).Layout(gtx, 1, func(gtx C, _ int) D {
return layout.Flex{
Alignment: layout.Middle,
Axis: layout.Vertical,
}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return alo.DefaultInset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Axis: layout.Vertical}.Layout(
gtx,
layout.Rigid(material.H5(th, "Simple downloader app using gioui").Layout),
layout.Rigid(material.Body1(th, `If you like this library and work like it, please consider sponsoring Elias and/or Chris!`).Layout),
)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return alo.DetailRow{}.Layout(gtx,
material.Body1(th, "Elias Naur can be sponsored on GitHub at "+sponsorEliasURL).Layout,
func(gtx C) D {
if p.eliasCopyButton.Clicked() {
clipboard.WriteOp{
Text: sponsorEliasURL,
}.Add(gtx.Ops)
}
return material.Button(th, &p.eliasCopyButton, "Copy Sponsorship URL").Layout(gtx)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return alo.DetailRow{}.Layout(gtx,
material.Body1(th, "Chris Waldon can be sponsored on GitHub at "+sponsorChrisURLGitHub+" and on Liberapay at "+sponsorChrisURLLiberapay).Layout,
func(gtx C) D {
if p.chrisCopyButtonGH.Clicked() {
clipboard.WriteOp{Text: sponsorChrisURLGitHub}.Add(gtx.Ops)
}
if p.chrisCopyButtonLP.Clicked() {
clipboard.WriteOp{Text: sponsorChrisURLLiberapay}.Add(gtx.Ops)
}
return alo.DefaultInset.Layout(gtx, func(gtx C) D {
return layout.Flex{}.Layout(gtx,
layout.Flexed(.5, material.Button(th, &p.chrisCopyButtonGH, "Copy GitHub URL").Layout),
layout.Flexed(.5, material.Button(th, &p.chrisCopyButtonLP, "Copy Liberapay URL").Layout),
)
})
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return alo.DetailRow{}.Layout(gtx,
material.Body1(th, "grab V3").Layout,
func(gtx C) D {
if p.grabV3.Clicked() {
clipboard.WriteOp{Text: grabV3}.Add(gtx.Ops)
}
return alo.DefaultInset.Layout(gtx, func(gtx C) D {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
return p.grabV3Field.Layout(gtx, th, "")
}),
layout.Flexed(.3, material.Button(th, &p.grabV3, "Copy").Layout),
)
})
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return alo.DetailRow{}.Layout(gtx,
material.Body1(th, "go-humanize").Layout,
func(gtx C) D {
if p.grabV3.Clicked() {
clipboard.WriteOp{Text: grabV3}.Add(gtx.Ops)
}
return alo.DefaultInset.Layout(gtx, func(gtx C) D {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
return p.humanizeField.Layout(gtx, th, "")
}),
layout.Flexed(.3, material.Button(th, &p.humanize, "Copy").Layout),
)
})
})
}),
)
})
}