-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgeometry.go
60 lines (45 loc) · 1.09 KB
/
geometry.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
package main
import (
"fmt"
)
type Geometry struct {
X, Y, W, H, B int16
// int16 for W, H and B (see "Why X Is Not Our Ideal Window System")
}
func (g Geometry) String() string {
return fmt.Sprintf("(%d,%d,%d,%d,%d)", g.X, g.Y, g.W, g.H, g.B)
}
func (g Geometry) Resize(i int16) Geometry {
return Geometry{g.X, g.Y, g.W + i, g.H + i, g.B}
}
func (g Geometry) ResizeWidth(i int16) Geometry {
return Geometry{g.X, g.Y, g.W + i, g.H, g.B}
}
func (g Geometry) ResizeHeight(i int16) Geometry {
return Geometry{g.X, g.Y, g.W, g.H + i, g.B}
}
func (g Geometry) ResizeBorder(i int16) Geometry {
bb := i + i
return Geometry{g.X, g.Y, g.W - bb, g.H - bb, g.B + i}
}
func (g Geometry) External() Geometry {
bb := g.B + g.B
return Geometry{g.X, g.Y, g.W + bb, g.H + bb, 0}
}
func (g Geometry) Position() (x, y int16) {
return g.X, g.Y
}
func (g Geometry) Size() (width, height int16) {
return g.W, g.H
}
type Orientation bool
const (
Vertical = Orientation(true)
Horizontal = Orientation(false)
)
func (o Orientation) String() string {
if o == Vertical {
return "vertical"
}
return "horizontal"
}