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

@ -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. // A Box draws a ASCII box around its contents, with an optional title and footer.
type Box struct { type Box struct {
x, y int x, y int
h, w int h, w int
title Drawable title Drawable
menuItems Drawable menuItems Drawable
contents Contents contents Contents
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 {
return &Box{ return &Box{
title: NewPaddedText(title), title: NewPaddedText(title),
menuItems: NewPaddedText(strings.Join(menuItems, " ")), menuItems: NewPaddedText(strings.Join(menuItems, " ")),
contents: contents, contents: contents,
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
} }