/
layout.go
59 lines (47 loc) · 1003 Bytes
/
layout.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 widget
import (
"image"
)
type Layouter interface {
PreferredSize(widgets []PreferredSizeLocateableWidget) (int, int)
Layout(widgets []PreferredSizeLocateableWidget, rect image.Rectangle)
}
type Relayoutable interface {
RequestRelayout()
}
type Locateable interface {
SetLocation(rect image.Rectangle)
}
type Locater interface {
WidgetAt(x int, y int) HasWidget
}
type Insets struct {
Top int
Left int
Right int
Bottom int
}
type Direction int
const (
DirectionHorizontal = Direction(iota)
DirectionVertical
)
func NewInsetsSimple(widthHeight int) Insets {
return Insets{
Top: widthHeight,
Left: widthHeight,
Right: widthHeight,
Bottom: widthHeight,
}
}
func (i Insets) Apply(rect image.Rectangle) image.Rectangle {
rect.Min = rect.Min.Add(image.Point{i.Left, i.Top})
rect.Max = rect.Max.Sub(image.Point{i.Right, i.Bottom})
return rect
}
func (i Insets) Dx() int {
return i.Left + i.Right
}
func (i Insets) Dy() int {
return i.Top + i.Bottom
}