-
Notifications
You must be signed in to change notification settings - Fork 0
/
constraint_pixel.go
45 lines (37 loc) · 1.06 KB
/
constraint_pixel.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
package zgui
// PixelConstraint is used to give an object an absolute position (in pixels)
// inside its parent.
type PixelConstraint struct {
IConstraint
val float32
}
// NewPixelConstraint creates a pixel constraint object.
func NewPixelConstraint(val float32) *PixelConstraint {
return &PixelConstraint{
IConstraint: NewBaseConstraint(),
val: val,
}
}
// GetX returns the absolute X position using parent's position as origin.
func (c PixelConstraint) GetX() float32 {
return c.parent().GetX() + c.val
}
// GetX returns the absolute Y position using parent's position as origin.
func (c PixelConstraint) GetY() float32 {
return c.parent().GetY() + c.val
}
// GetX returns the absolute Width value.
func (c PixelConstraint) GetWidth() float32 {
return c.val
}
// GetX returns the absolute Height value.
func (c PixelConstraint) GetHeight() float32 {
return c.val
}
func (c *PixelConstraint) move(d float32) {
c.val += d
}
// String returns a string representation of the constraint.
func (c PixelConstraint) String() string {
return "PixelConstraint"
}