/
style.go
142 lines (121 loc) · 2.8 KB
/
style.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
package renderers
import (
"strings"
"gioui.org/font"
"gioui.org/layout"
"gioui.org/unit"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/values"
)
func getLabel(lbl cryptomaterial.Label) cryptomaterial.Label {
return lbl
}
func setStyle(lbl *cryptomaterial.Label, style string) {
var s font.Style
switch style {
case "italic":
s = font.Italic
case "regular":
s = font.Regular
}
lbl.Font.Style = s
}
func setWeight(lbl *cryptomaterial.Label, weight string) {
var w font.Weight
switch weight {
case "normal":
w = font.Normal
case "medium":
w = font.Medium
case "bold", "strong":
w = font.Bold
default:
w = lbl.Font.Weight
}
lbl.Font.Weight = w
}
func getHeading(txt string, level int, theme *cryptomaterial.Theme) cryptomaterial.Label {
textSize := values.TextSize16
switch level {
case 1:
textSize = values.TextSize28
case 2:
textSize = values.TextSize24
case 3:
textSize = values.TextSize20
case 4:
textSize = values.TextSize16
case 5:
textSize = values.TextSize14
case 6:
textSize = values.TextSize13_6
}
lbl := theme.H1(txt)
lbl.Font.Weight = font.Bold
lbl.TextSize = textSize
return lbl
}
func renderStrike(lbl cryptomaterial.Label, theme *cryptomaterial.Theme) layout.Widget {
return func(gtx C) D {
var dims D
return layout.Stack{}.Layout(gtx,
layout.Stacked(func(gtx C) D {
dims = lbl.Layout(gtx)
return dims
}),
layout.Expanded(func(gtx C) D {
return layout.Inset{
Top: unit.Dp((float32(dims.Size.Y) / float32(2))),
}.Layout(gtx, func(gtx C) D {
l := theme.Separator()
l.Color = lbl.Color
l.Width = dims.Size.X
return l.Layout(gtx)
})
}),
)
}
}
func renderBlockQuote(lbl cryptomaterial.Label, theme *cryptomaterial.Theme) layout.Widget {
words := strings.Fields(lbl.Text)
return func(gtx C) D {
var dims D
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Flexed(1, func(gtx C) D {
l := theme.SeparatorVertical(dims.Size.Y, 10)
l.Color = theme.Color.Gray2
return l.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
dims = layout.Inset{
Left: unit.Dp(4),
}.Layout(gtx, func(gtx C) D {
return cryptomaterial.GridWrap{
Axis: layout.Horizontal,
Alignment: layout.Start,
}.Layout(gtx, len(words), func(gtx C, i int) D {
lbl.Text = words[i] + " "
return lbl.Layout(gtx)
})
})
return dims
}),
)
}
}
func renderHorizontalLine(theme *cryptomaterial.Theme) layout.Widget {
l := theme.Separator()
l.Width = 1
return l.Layout
}
func renderEmptyLine(theme *cryptomaterial.Theme, isList bool) layout.Widget {
padding := -5
if isList {
padding = -10
}
return func(gtx C) D {
dims := theme.Body2("").Layout(gtx)
dims.Size.Y = dims.Size.Y + padding
return dims
}
}