-
Notifications
You must be signed in to change notification settings - Fork 2
/
padding.go
55 lines (47 loc) · 1.15 KB
/
padding.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
package dos
import "github.com/gdamore/tcell/v2"
type Padding struct {
Child Widget
Top int
Right int
Bottom int
Left int
}
func (p *Padding) GetChildRect(currentRect Rect) Rect {
return Rect{
currentRect.X + p.Left,
currentRect.Y + p.Top,
currentRect.W - p.Left - p.Right,
currentRect.H - p.Top - p.Bottom,
}
}
func (p *Padding) HandleMouse(currentRect Rect, ev *tcell.EventMouse) bool {
if p.Child != nil {
return p.Child.HandleMouse(p.GetChildRect(currentRect), ev)
}
return false
}
func (p *Padding) HandleKey(ev *tcell.EventKey) bool {
if p.Child != nil {
return p.Child.HandleKey(ev)
}
return false
}
func (p *Padding) SetFocused(b bool) {
if p.Child != nil {
p.Child.SetFocused(b)
}
}
func (p *Padding) DisplaySize(boundsW, boundsH int) (w, h int) {
if p.Child != nil {
w, h = p.Child.DisplaySize(boundsW-p.Left-p.Right, boundsH-p.Top-p.Bottom)
return w + p.Left + p.Right, h + p.Top + p.Bottom
}
return 0, 0
}
func (p *Padding) Draw(rect Rect, s tcell.Screen) {
if p.Child != nil {
DrawRect(p.GetChildRect(rect), ' ', tcell.Style{}.Background(tcell.ColorYellow), s)
p.Child.Draw(p.GetChildRect(rect), s)
}
}