make boxes cover anything behind them

This commit is contained in:
David 2021-08-01 11:05:51 -04:00
parent 4ec1a85139
commit bb01987b3b
1 changed files with 29 additions and 14 deletions

View File

@ -185,24 +185,26 @@ func (c *Container) SetContents(con Contents) {
// A Box draws a ASCII box around its contents, with an optional title and footer.
type Box struct {
x, y int
h, w int
title Drawable
menuItems Drawable
contents Contents
style tcell.Style
cascade bool
visible bool
x, y int
h, w int
title Drawable
menuItems Drawable
contents Contents
style tcell.Style
cascade bool
visible bool
transparent bool
}
func NewBox(title string, menuItems []string, contents Contents, initialStyle tcell.Style, cascade bool) *Box {
return &Box{
title: NewPaddedText(title),
menuItems: NewPaddedText(strings.Join(menuItems, " ")),
contents: contents,
style: initialStyle,
cascade: cascade,
visible: true,
title: NewPaddedText(title),
menuItems: NewPaddedText(strings.Join(menuItems, " ")),
contents: contents,
style: initialStyle,
cascade: cascade,
visible: true,
transparent: false,
}
}
@ -223,6 +225,15 @@ func (b *Box) Draw(s tcell.Screen) {
if !b.visible {
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++ {
s.SetContent(m, b.y, 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
}
func (b *Box) SetTransparent(v bool) {
b.transparent = v
}
func (b *Box) Contents() Contents {
return b.contents
}