-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
fill.go
114 lines (96 loc) · 2.94 KB
/
fill.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
// Copyright (c) 2017 Andrey Gayvoronsky <plandem@gmail.com>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package styles
import (
"github.com/plandem/xlsx/internal/color"
"github.com/plandem/xlsx/internal/ml"
"github.com/plandem/xlsx/internal/ml/primitives"
)
type patternOption byte
type gradientOption byte
//N.B.: only one kind of fill is allowed by standard
type fillOption struct {
Pattern patternOption
Gradient gradientOption
}
//Fill is a 'namespace' for all possible settings for fill
var Fill fillOption
func (f *fillOption) Color(rgb string) Option {
return func(s *Info) {
s.styleInfo.Fill.Pattern.Color = color.New(rgb)
s.styleInfo.Fill.Gradient = &ml.GradientFill{}
}
}
func (f *fillOption) Background(rgb string) Option {
return func(s *Info) {
s.styleInfo.Fill.Pattern.Background = color.New(rgb)
s.styleInfo.Fill.Gradient = &ml.GradientFill{}
}
}
func (f *fillOption) Type(pt primitives.PatternType) Option {
return func(s *Info) {
s.styleInfo.Fill.Pattern.Type = pt
s.styleInfo.Fill.Gradient = &ml.GradientFill{}
}
}
func (p *patternOption) Color(rgb string) Option {
return func(s *Info) {
s.styleInfo.Fill.Pattern.Color = color.New(rgb)
s.styleInfo.Fill.Gradient = &ml.GradientFill{}
}
}
func (p *patternOption) Background(rgb string) Option {
return func(s *Info) {
s.styleInfo.Fill.Pattern.Background = color.New(rgb)
s.styleInfo.Fill.Gradient = &ml.GradientFill{}
}
}
func (p *patternOption) Type(pt primitives.PatternType) Option {
return func(s *Info) {
s.styleInfo.Fill.Pattern.Type = pt
s.styleInfo.Fill.Gradient = &ml.GradientFill{}
}
}
func (g *gradientOption) Type(gt primitives.GradientType) Option {
return func(s *Info) {
s.styleInfo.Fill.Gradient.Type = gt
s.styleInfo.Fill.Pattern = &ml.PatternFill{}
}
}
func (g *gradientOption) Degree(degree float64) Option {
return func(s *Info) {
s.styleInfo.Fill.Gradient.Degree = degree
s.styleInfo.Fill.Pattern = &ml.PatternFill{}
}
}
func (g *gradientOption) Left(left float64) Option {
return func(s *Info) {
s.styleInfo.Fill.Gradient.Left = left
s.styleInfo.Fill.Pattern = &ml.PatternFill{}
}
}
func (g *gradientOption) Right(right float64) Option {
return func(s *Info) {
s.styleInfo.Fill.Gradient.Right = right
s.styleInfo.Fill.Pattern = &ml.PatternFill{}
}
}
func (g *gradientOption) Top(top float64) Option {
return func(s *Info) {
s.styleInfo.Fill.Gradient.Top = top
s.styleInfo.Fill.Pattern = &ml.PatternFill{}
}
}
func (g *gradientOption) Bottom(bottom float64) Option {
return func(s *Info) {
s.styleInfo.Fill.Gradient.Bottom = bottom
s.styleInfo.Fill.Pattern = &ml.PatternFill{}
}
}
func (g *gradientOption) Stop(position float64, rgb string) Option {
return func(s *Info) {
s.styleInfo.Fill.Gradient.Stop = append(s.styleInfo.Fill.Gradient.Stop, &ml.GradientStop{Position: position, Color: color.New(rgb)})
s.styleInfo.Fill.Pattern = &ml.PatternFill{}
}
}