add missing SetVisible changes

This commit is contained in:
David 2021-07-28 21:39:37 -04:00
parent 90a9facc44
commit 49b8f675df

View File

@ -12,6 +12,7 @@ type Drawable interface {
Draw(tcell.Screen) Draw(tcell.Screen)
SetSize(x, y, h, w int) SetSize(x, y, h, w int)
SetStyle(tcell.Style) SetStyle(tcell.Style)
SetVisible(bool)
} }
type Offsets struct { type Offsets struct {
@ -50,16 +51,21 @@ type Container struct {
h, w int h, w int
layoutMethod int layoutMethod int
contents Contents contents Contents
visible bool
} }
func NewContainer(contents Contents, layoutMethod int) *Container { func NewContainer(contents Contents, layoutMethod int) *Container {
return &Container{ return &Container{
layoutMethod: layoutMethod, layoutMethod: layoutMethod,
contents: contents, contents: contents,
visible: true,
} }
} }
func (c *Container) Draw(s tcell.Screen) { func (c *Container) Draw(s tcell.Screen) {
if !c.visible {
return
}
for i := range c.contents { for i := range c.contents {
c.contents[i].Container.Draw(s) c.contents[i].Container.Draw(s)
} }
@ -165,6 +171,10 @@ func (c *Container) SetStyle(s tcell.Style) {
// containers have no visible elements to style // containers have no visible elements to style
} }
func (c *Container) SetVisible(b bool) {
c.visible = b
}
func (c *Container) Contents() Contents { func (c *Container) Contents() Contents {
return c.contents return c.contents
} }
@ -182,6 +192,7 @@ type Box struct {
contents Contents contents Contents
style tcell.Style style tcell.Style
cascade bool cascade bool
visible 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 {
@ -191,6 +202,7 @@ func NewBox(title string, menuItems []string, contents Contents, initialStyle tc
contents: contents, contents: contents,
style: initialStyle, style: initialStyle,
cascade: cascade, cascade: cascade,
visible: true,
} }
} }
@ -208,6 +220,9 @@ func (b *Box) SetSize(x, y, h, w int) {
} }
func (b *Box) Draw(s tcell.Screen) { func (b *Box) Draw(s tcell.Screen) {
if !b.visible {
return
}
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)
@ -243,6 +258,10 @@ func (b *Box) SetStyle(s tcell.Style) {
} }
} }
func (b *Box) SetVisible(v bool) {
b.visible = v
}
func (b *Box) Contents() Contents { func (b *Box) Contents() Contents {
return b.contents return b.contents
} }
@ -258,6 +277,7 @@ type List struct {
selected int selected int
listItems []ListKeyValue listItems []ListKeyValue
style tcell.Style style tcell.Style
visible bool
} }
type ListKeyValue struct { type ListKeyValue struct {
@ -269,6 +289,7 @@ func NewList(listItems []ListKeyValue, initialSelected int) *List {
return &List{ return &List{
listItems: listItems, listItems: listItems,
selected: initialSelected, selected: initialSelected,
visible: true,
} }
} }
@ -277,6 +298,9 @@ func (l *List) SetSize(x, y, h, w int) {
} }
func (l *List) Draw(s tcell.Screen) { func (l *List) Draw(s tcell.Screen) {
if !l.visible {
return
}
for i := range l.listItems { for i := range l.listItems {
for j, r := range l.listItems[i].Value { for j, r := range l.listItems[i].Value {
s.SetContent(l.x+j, l.y+i, r, nil, l.style) s.SetContent(l.x+j, l.y+i, r, nil, l.style)
@ -287,6 +311,10 @@ func (l *List) Draw(s tcell.Screen) {
} }
} }
func (l *List) SetVisible(b bool) {
l.visible = b
}
func (l *List) SetStyle(s tcell.Style) { func (l *List) SetStyle(s tcell.Style) {
l.style = s l.style = s
} }
@ -316,11 +344,13 @@ type BookDetails struct {
h, w int h, w int
book *book.Book book *book.Book
style tcell.Style style tcell.Style
visible bool
} }
func NewBookDetails(b *book.Book) *BookDetails { func NewBookDetails(b *book.Book) *BookDetails {
return &BookDetails{ return &BookDetails{
book: b, book: b,
visible: true,
} }
} }
@ -336,6 +366,9 @@ func (l *BookDetails) Draw(s tcell.Screen) {
if l.book == nil { if l.book == nil {
return return
} }
if !l.visible {
return
}
items := []struct { items := []struct {
label string label string
value string value string
@ -367,6 +400,10 @@ func (l *BookDetails) Draw(s tcell.Screen) {
} }
} }
func (l *BookDetails) SetVisible(b bool) {
l.visible = b
}
func (l *BookDetails) SetStyle(s tcell.Style) { func (l *BookDetails) SetStyle(s tcell.Style) {
l.style = s l.style = s
} }
@ -378,10 +415,11 @@ type PaddedText struct {
h, w int h, w int
text string text string
style tcell.Style style tcell.Style
visible bool
} }
func NewPaddedText(text string) *PaddedText { func NewPaddedText(text string) *PaddedText {
return &PaddedText{text: text} return &PaddedText{text: text, visible: true}
} }
func (p *PaddedText) SetSize(x, y, _, _ int) { func (p *PaddedText) SetSize(x, y, _, _ int) {
@ -396,6 +434,9 @@ func (p *PaddedText) Draw(s tcell.Screen) {
if p.text == "" { if p.text == "" {
return return
} }
if !p.visible {
return
}
t := p.x t := p.x
s.SetContent(t, p.y, ' ', nil, p.style) s.SetContent(t, p.y, ' ', nil, p.style)
t++ t++
@ -406,6 +447,10 @@ func (p *PaddedText) Draw(s tcell.Screen) {
s.SetContent(t, p.y, ' ', nil, p.style) s.SetContent(t, p.y, ' ', nil, p.style)
} }
func (p *PaddedText) SetVisible(b bool) {
p.visible = b
}
type KeyValue struct { type KeyValue struct {
x, y int x, y int
h, w int h, w int
@ -413,6 +458,7 @@ type KeyValue struct {
value string value string
separator string separator string
style tcell.Style style tcell.Style
visible bool
} }
func NewKeyValue(key, separator, value string) *KeyValue { func NewKeyValue(key, separator, value string) *KeyValue {
@ -420,6 +466,7 @@ func NewKeyValue(key, separator, value string) *KeyValue {
key: key, key: key,
separator: separator, separator: separator,
value: value, value: value,
visible: true,
} }
} }
@ -432,6 +479,9 @@ func (p *KeyValue) SetStyle(s tcell.Style) {
} }
func (p *KeyValue) Draw(s tcell.Screen) { func (p *KeyValue) Draw(s tcell.Screen) {
if !p.visible {
return
}
for j, r := range p.key { for j, r := range p.key {
s.SetContent(p.x+j, p.y, r, nil, p.style) s.SetContent(p.x+j, p.y, r, nil, p.style)
} }
@ -443,6 +493,10 @@ func (p *KeyValue) Draw(s tcell.Screen) {
} }
} }
func (p *KeyValue) SetVisible(b bool) {
p.visible = b
}
func (p *KeyValue) GetValue() string { func (p *KeyValue) GetValue() string {
return p.value return p.value
} }