-
Notifications
You must be signed in to change notification settings - Fork 1
/
border.go
85 lines (68 loc) · 1.79 KB
/
border.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
85
package tooey
import "github.com/gdamore/tcell/v2"
// NewDefaultBorder returns a border with the default character set
func NewDefaultBorder(theme *Theme) *Border {
if theme == nil {
theme = DefaultTheme
}
return &Border{
Enabled: true,
Theme: theme,
Chars: theme.Chars,
Left: true,
Top: true,
Right: true,
Bottom: true,
}
}
// Border contains the definition and drawing logic
// of an element border
type Border struct {
Enabled bool
Theme *Theme
Chars *Chars
Left bool
Top bool
Right bool
Bottom bool
}
// SetChars sets the char map for borders
func (b *Border) SetChars(chars *Chars) {
b.Chars = chars
}
// Draw the borders for the given rect to the given tcell.Screen
func (b *Border) Draw(s tcell.Screen, rect *Rectangle) {
if b.Enabled {
for col := rect.X1(); col <= rect.X2(); col++ {
if b.Top {
s.SetContent(col, rect.Y1(), b.Chars.HLine, nil, b.Theme.Border.Style)
}
if b.Bottom {
s.SetContent(col, rect.Y2(), b.Chars.HLine, nil, b.Theme.Border.Style)
}
}
for row := rect.Y1(); row <= rect.Y2(); row++ {
if b.Left {
s.SetContent(rect.X1(), row, b.Chars.VLine, nil, b.Theme.Border.Style)
}
if b.Right {
s.SetContent(rect.X2(), row, b.Chars.VLine, nil, b.Theme.Border.Style)
}
}
// Patch corners as necessary
if !rect.ZeroSize() {
if b.Top && b.Left {
s.SetContent(rect.X1(), rect.Y1(), b.Chars.ULCorner, nil, b.Theme.Border.Style)
}
if b.Top && b.Right {
s.SetContent(rect.X2(), rect.Y1(), b.Chars.URCorner, nil, b.Theme.Border.Style)
}
if b.Left && b.Bottom {
s.SetContent(rect.X1(), rect.Y2(), b.Chars.LLCorner, nil, b.Theme.Border.Style)
}
if b.Bottom && b.Right {
s.SetContent(rect.X2(), rect.Y2(), b.Chars.LRCorner, nil, b.Theme.Border.Style)
}
}
}
}