-
Notifications
You must be signed in to change notification settings - Fork 9
/
background_position.go
54 lines (46 loc) · 1.49 KB
/
background_position.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 props
import (
"fmt"
"strings"
)
type (
BackgroundPosition string
BackgroundPositionEdge struct {
Position BackgroundPosition
Unit Unit
}
)
const (
BackgroundPositionTop BackgroundPosition = "top"
BackgroundPositionBottom BackgroundPosition = "bottom"
BackgroundPositionLeft BackgroundPosition = "left"
BackgroundPositionRight BackgroundPosition = "right"
BackgroundPositionCenter BackgroundPosition = "center"
BackgroundPositionTopLeft BackgroundPosition = "top left"
BackgroundPositionTopRight BackgroundPosition = "top right"
BackgroundPositionBottomLeft BackgroundPosition = "bottom left"
BackgroundPositionBottomRight BackgroundPosition = "bottom right"
)
func (b BackgroundPosition) String() string {
return string(b)
}
func (b BackgroundPositionEdge) String() string {
return strings.TrimSpace(fmt.Sprintf("%s %s", b.Position, b.Unit))
}
func BackgroundPositionXY(x, y Unit) BackgroundPosition {
return BackgroundPosition(fmt.Sprintf("%s %s", x.String(), y.String()))
}
func BackgroundPositionEdges(edges ...BackgroundPositionEdge) BackgroundPosition {
ed := make([]string, len(edges))
for i, edge := range edges {
ed[i] = edge.String()
}
return BackgroundPosition(strings.Join(ed, " "))
}
func BackgroundPositions(positions ...BackgroundPosition) BackgroundPosition {
po := make([]string, len(positions))
for i, position := range positions {
po[i] = string(position)
}
return BackgroundPosition(strings.Join(po, ","))
}