-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathdrawableContainer.go
84 lines (68 loc) · 2.08 KB
/
drawableContainer.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
74
75
76
77
78
79
80
81
82
83
84
package termuiRenders
import (
"github.com/gizak/termui/v3"
)
const topHeight = 22
// DrawableContainer defines a container of drawable object with position and dimensions
type DrawableContainer struct {
topLeft termui.Drawable
topRight termui.Drawable
bottom termui.Drawable
minHeight int
minWidth int
maxWidth int
maxHeight int
}
//NewDrawableContainer method is used to return a new NewDrawableContainer structure
func NewDrawableContainer() *DrawableContainer {
dc := DrawableContainer{}
return &dc
}
// TopLeft gets the topLeft drawable
func (imh *DrawableContainer) TopLeft() termui.Drawable {
return imh.topLeft
}
// SetTopLeft sets the topLeft drawable
func (imh *DrawableContainer) SetTopLeft(drawable termui.Drawable) {
imh.topLeft = drawable
}
// TopRight sets the topRight drawable
func (imh *DrawableContainer) TopRight() termui.Drawable {
return imh.topRight
}
// SetTopRight sets the topRight drawable
func (imh *DrawableContainer) SetTopRight(drawable termui.Drawable) {
imh.topRight = drawable
}
// Bottom sets the bottom drawable
func (imh *DrawableContainer) Bottom() termui.Drawable {
return imh.bottom
}
// SetBottom sets the bottom drawable
func (imh *DrawableContainer) SetBottom(drawable termui.Drawable) {
imh.bottom = drawable
}
// Items returns the containing items list
func (imh *DrawableContainer) Items() []termui.Drawable {
items := make([]termui.Drawable, 0)
items = append(items, imh.topLeft)
items = append(items, imh.topRight)
items = append(items, imh.bottom)
return items
}
// SetRectangle sets the rectangle of this drawable object
func (imh *DrawableContainer) SetRectangle(startWidth, startHeight, termWidth, termHeight int) {
imh.maxWidth = termWidth
imh.maxHeight = termHeight
imh.minWidth = startWidth
imh.minHeight = startHeight
if imh.topLeft != nil {
imh.topLeft.SetRect(startWidth, startHeight, imh.maxWidth/2, topHeight)
}
if imh.topRight != nil {
imh.topRight.SetRect(imh.maxWidth/2, startHeight, imh.maxWidth, topHeight)
}
if imh.bottom != nil {
imh.bottom.SetRect(startWidth, topHeight, imh.maxWidth, imh.maxHeight)
}
}