-
Notifications
You must be signed in to change notification settings - Fork 21
/
line.go
70 lines (59 loc) · 1.19 KB
/
line.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
package cryptomaterial
import (
"image"
"image/color"
"gioui.org/layout"
"gioui.org/op/clip"
"gioui.org/op/paint"
)
type (
// Line represents a rectangle widget with an initial thickness of 1
Line struct {
Height int
Width int
Color color.NRGBA
isVertical bool
}
)
// SeparatorVertical returns a vertical line widget instance
func (t *Theme) SeparatorVertical(height, width int) Line {
vLine := t.Line(height, width)
vLine.isVertical = true
return vLine
}
// Line returns a line widget instance
func (t *Theme) Line(height, width int) Line {
if height == 0 {
height = 1
}
col := t.Color.Primary
col.A = 150
return Line{
Height: height,
Width: width,
Color: col,
}
}
func (t *Theme) Separator() Line {
l := t.Line(1, 0)
l.Color = t.Color.Gray3
return l
}
// Layout renders the line widget
func (l Line) Layout(gtx C) D {
if l.Width == 0 {
l.Width = gtx.Constraints.Max.X
}
if l.isVertical && l.Height == 0 {
l.Height = gtx.Constraints.Max.Y
}
line := image.Rectangle{
Max: image.Point{
X: l.Width,
Y: l.Height,
},
}
defer clip.Rect(line).Push(gtx.Ops).Pop()
paint.Fill(gtx.Ops, l.Color)
return layout.Dimensions{Size: line.Max}
}