-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpadding.go
54 lines (47 loc) · 864 Bytes
/
padding.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
package bento
type Padding struct {
Top, Right, Bottom, Left int
}
func NewPadding(sides ...int) Padding {
switch len(sides) {
case 0:
return Padding{}
case 1:
side := sides[0]
return Padding{Top: side, Right: side, Bottom: side, Left: side}
case 2:
vertical := sides[0]
horizontal := sides[1]
return Padding{
Top: vertical,
Right: horizontal,
Bottom: vertical,
Left: horizontal,
}
case 4:
return Padding{
Top: sides[0],
Right: sides[1],
Bottom: sides[2],
Left: sides[3],
}
default:
panic("unexpected sides count")
}
}
func (p Padding) WithTop(s int) Padding {
p.Top = s
return p
}
func (p Padding) WithRight(s int) Padding {
p.Right = s
return p
}
func (p Padding) WithBottom(s int) Padding {
p.Bottom = s
return p
}
func (p Padding) WithLeft(s int) Padding {
p.Bottom = s
return p
}