make boxes cover anything behind them

This commit is contained in:
David 2021-08-01 11:05:51 -04:00
parent 4ec1a85139
commit bb01987b3b

View File

@ -193,6 +193,7 @@ type Box struct {
style tcell.Style style tcell.Style
cascade bool cascade bool
visible bool visible bool
transparent bool
} }
func NewBox(title string, menuItems []string, contents Contents, initialStyle tcell.Style, cascade bool) *Box { func NewBox(title string, menuItems []string, contents Contents, initialStyle tcell.Style, cascade bool) *Box {
@ -203,6 +204,7 @@ func NewBox(title string, menuItems []string, contents Contents, initialStyle tc
style: initialStyle, style: initialStyle,
cascade: cascade, cascade: cascade,
visible: true, visible: true,
transparent: false,
} }
} }
@ -223,6 +225,15 @@ func (b *Box) Draw(s tcell.Screen) {
if !b.visible { if !b.visible {
return return
} }
// blank out inner area
if !b.transparent {
for m := b.x + 1; m < b.x+b.w-1; m++ {
for n := b.y + 1; n < b.y+b.h-1; n++ {
s.SetContent(m, n, ' ', nil, b.style)
}
}
}
// draw outside bars
for m := b.x + 1; m < b.x+b.w-1; m++ { for m := b.x + 1; m < b.x+b.w-1; m++ {
s.SetContent(m, b.y, tcell.RuneHLine, nil, b.style) s.SetContent(m, b.y, tcell.RuneHLine, nil, b.style)
s.SetContent(m, b.y+b.h-1, tcell.RuneHLine, nil, b.style) s.SetContent(m, b.y+b.h-1, tcell.RuneHLine, nil, b.style)
@ -262,6 +273,10 @@ func (b *Box) SetVisible(v bool) {
b.visible = v b.visible = v
} }
func (b *Box) SetTransparent(v bool) {
b.transparent = v
}
func (b *Box) Contents() Contents { func (b *Box) Contents() Contents {
return b.contents return b.contents
} }