-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathborder.go
77 lines (67 loc) · 1.86 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
package dull
// Border defines a border for a rectangle of cells.
//
// The border will be rendered just inside the cells of
// the rectangle defined by the cell values.
type Border struct {
// The leftmost column.
// The border will drawn down the left side of cells in this column.
leftColumn int
// The rightmost column.
// The border will drawn down the right side of cells in this column.
rightColumn int
// The topmost row.
// The border will drawn across the top side of cells in this row.
topRow int
// The bottommost row.
// The border will drawn across the bottom side of cells in this row.
bottomRow int
// The color to use to draw the border.
// The alpha value will typically be less than 1.0 to
// leave glyphs in border cells readable.
color Color
}
func NewBorder(leftColumn, rightColumn, topRow, bottomRow int, color Color) Border {
return Border{
leftColumn: leftColumn,
rightColumn: rightColumn,
topRow: topRow,
bottomRow: bottomRow,
color: color,
}
}
// BorderId is an identifier provided when adding a border.
// It may later be used to remove a border.
type BorderId int
// Borders represents a collection of borders that a window may render.
//
// An instance is provided by a Window.
type Borders struct {
nextId BorderId
borders map[BorderId]Border
}
func NewBorders() *Borders {
return &Borders{
nextId: 0,
borders: make(map[BorderId]Border),
}
}
// Add adds a border.
//
// The returned BorderId may be later used to remove the border.
func (b *Borders) Add(border Border) BorderId {
b.nextId++
id := b.nextId
b.borders[id] = border
return id
}
// Removes a border.
//
// The border is identified by an id returned from the Add function.
func (b *Borders) Remove(id BorderId) {
delete(b.borders, id)
}
// RemoveAll removes all borders.
func (b *Borders) RemoveAll() {
b.borders = make(map[BorderId]Border)
}