-
Notifications
You must be signed in to change notification settings - Fork 0
/
rectangle.go
73 lines (57 loc) · 1.25 KB
/
rectangle.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
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package walk
import (
"github.com/lxn/win"
)
// Rectangle defines upper left corner with width and height region in 1/96" units, or native
// pixels, or grid rows and columns.
type Rectangle struct {
X, Y, Width, Height int
}
func rectangleFromRECT(r win.RECT) Rectangle {
return Rectangle{
X: int(r.Left),
Y: int(r.Top),
Width: int(r.Right - r.Left),
Height: int(r.Bottom - r.Top),
}
}
func (r Rectangle) Left() int {
return r.X
}
func (r Rectangle) Top() int {
return r.Y
}
func (r Rectangle) Right() int {
return r.X + r.Width - 1
}
func (r Rectangle) Bottom() int {
return r.Y + r.Height - 1
}
func (r Rectangle) Location() Point {
return Point{r.X, r.Y}
}
func (r *Rectangle) SetLocation(p Point) Rectangle {
r.X = p.X
r.Y = p.Y
return *r
}
func (r Rectangle) Size() Size {
return Size{r.Width, r.Height}
}
func (r *Rectangle) SetSize(s Size) Rectangle {
r.Width = s.Width
r.Height = s.Height
return *r
}
func (r Rectangle) toRECT() win.RECT {
return win.RECT{
int32(r.X),
int32(r.Y),
int32(r.X + r.Width),
int32(r.Y + r.Height),
}
}