From bb01987b3b7e0725387a79f440e64ea3942e4178 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 1 Aug 2021 11:05:51 -0400 Subject: [PATCH] make boxes cover anything behind them --- ui/ui.go | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/ui/ui.go b/ui/ui.go index c15ae9d..cc3e0ce 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -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 }