-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstraint.go
36 lines (26 loc) · 1.01 KB
/
constraint.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
package bento
import "fmt"
type Constraint interface {
fmt.Stringer
isConstraint()
}
type (
ConstraintMin int
ConstraintMax int
ConstraintLen int
ConstraintPercentage int
ConstraintRatio struct{ Num, Den int }
ConstraintFill int
)
func (m ConstraintMin) String() string { return fmt.Sprintf("Min(%d)", m) }
func (ConstraintMin) isConstraint() {}
func (m ConstraintMax) String() string { return fmt.Sprintf("Max(%d)", m) }
func (ConstraintMax) isConstraint() {}
func (l ConstraintLen) String() string { return fmt.Sprintf("Len(%d)", l) }
func (ConstraintLen) isConstraint() {}
func (p ConstraintPercentage) String() string { return fmt.Sprintf("Percentage(%d)", p) }
func (ConstraintPercentage) isConstraint() {}
func (r ConstraintRatio) String() string { return fmt.Sprintf("Ratio(%d / %d)", r.Num, r.Den) }
func (ConstraintRatio) isConstraint() {}
func (f ConstraintFill) String() string { return fmt.Sprintf("Fill(%d)", f) }
func (ConstraintFill) isConstraint() {}