-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstraint_operational.go
43 lines (35 loc) · 1.1 KB
/
constraint_operational.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
package zgui
type operation func(IConstraint) float32
// OperationalConstraint is similar to RelativeConstraint but allows to
// use any parent bound to calculate.
type OperationalConstraint struct {
IConstraint
op operation
}
// NewOperationalConstraint creates a operational constraint object.
func NewOperationalConstraint(op operation) *OperationalConstraint {
return &OperationalConstraint{
IConstraint: NewBaseConstraint(),
op: op,
}
}
// GetX returns the result of calling the operation.
func (c OperationalConstraint) GetX() float32 {
return c.op(c)
}
// GetY returns parent's Y multiplied by the multiplier.
func (c OperationalConstraint) GetY() float32 {
return c.op(c)
}
// GetWidth returns parent's Width multiplied by the multiplier.
func (c OperationalConstraint) GetWidth() float32 {
return c.op(c)
}
// GetHeight returns parent's Height multiplied by the multiplier.
func (c OperationalConstraint) GetHeight() float32 {
return c.op(c)
}
// String returns a string representation of the constraint.
func (c OperationalConstraint) String() string {
return "OperationalConstraint"
}