add missing SetVisible changes
This commit is contained in:
parent
90a9facc44
commit
49b8f675df
56
ui/ui.go
56
ui/ui.go
@ -12,6 +12,7 @@ type Drawable interface {
|
||||
Draw(tcell.Screen)
|
||||
SetSize(x, y, h, w int)
|
||||
SetStyle(tcell.Style)
|
||||
SetVisible(bool)
|
||||
}
|
||||
|
||||
type Offsets struct {
|
||||
@ -50,16 +51,21 @@ type Container struct {
|
||||
h, w int
|
||||
layoutMethod int
|
||||
contents Contents
|
||||
visible bool
|
||||
}
|
||||
|
||||
func NewContainer(contents Contents, layoutMethod int) *Container {
|
||||
return &Container{
|
||||
layoutMethod: layoutMethod,
|
||||
contents: contents,
|
||||
visible: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Container) Draw(s tcell.Screen) {
|
||||
if !c.visible {
|
||||
return
|
||||
}
|
||||
for i := range c.contents {
|
||||
c.contents[i].Container.Draw(s)
|
||||
}
|
||||
@ -165,6 +171,10 @@ func (c *Container) SetStyle(s tcell.Style) {
|
||||
// containers have no visible elements to style
|
||||
}
|
||||
|
||||
func (c *Container) SetVisible(b bool) {
|
||||
c.visible = b
|
||||
}
|
||||
|
||||
func (c *Container) Contents() Contents {
|
||||
return c.contents
|
||||
}
|
||||
@ -182,6 +192,7 @@ type Box struct {
|
||||
contents Contents
|
||||
style tcell.Style
|
||||
cascade bool
|
||||
visible bool
|
||||
}
|
||||
|
||||
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,
|
||||
style: initialStyle,
|
||||
cascade: cascade,
|
||||
visible: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,6 +220,9 @@ func (b *Box) SetSize(x, y, h, w int) {
|
||||
}
|
||||
|
||||
func (b *Box) Draw(s tcell.Screen) {
|
||||
if !b.visible {
|
||||
return
|
||||
}
|
||||
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)
|
||||
@ -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 {
|
||||
return b.contents
|
||||
}
|
||||
@ -258,6 +277,7 @@ type List struct {
|
||||
selected int
|
||||
listItems []ListKeyValue
|
||||
style tcell.Style
|
||||
visible bool
|
||||
}
|
||||
|
||||
type ListKeyValue struct {
|
||||
@ -269,6 +289,7 @@ func NewList(listItems []ListKeyValue, initialSelected int) *List {
|
||||
return &List{
|
||||
listItems: listItems,
|
||||
selected: initialSelected,
|
||||
visible: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,6 +298,9 @@ func (l *List) SetSize(x, y, h, w int) {
|
||||
}
|
||||
|
||||
func (l *List) Draw(s tcell.Screen) {
|
||||
if !l.visible {
|
||||
return
|
||||
}
|
||||
for i := range l.listItems {
|
||||
for j, r := range l.listItems[i].Value {
|
||||
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) {
|
||||
l.style = s
|
||||
}
|
||||
@ -316,11 +344,13 @@ type BookDetails struct {
|
||||
h, w int
|
||||
book *book.Book
|
||||
style tcell.Style
|
||||
visible bool
|
||||
}
|
||||
|
||||
func NewBookDetails(b *book.Book) *BookDetails {
|
||||
return &BookDetails{
|
||||
book: b,
|
||||
visible: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,6 +366,9 @@ func (l *BookDetails) Draw(s tcell.Screen) {
|
||||
if l.book == nil {
|
||||
return
|
||||
}
|
||||
if !l.visible {
|
||||
return
|
||||
}
|
||||
items := []struct {
|
||||
label 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) {
|
||||
l.style = s
|
||||
}
|
||||
@ -378,10 +415,11 @@ type PaddedText struct {
|
||||
h, w int
|
||||
text string
|
||||
style tcell.Style
|
||||
visible bool
|
||||
}
|
||||
|
||||
func NewPaddedText(text string) *PaddedText {
|
||||
return &PaddedText{text: text}
|
||||
return &PaddedText{text: text, visible: true}
|
||||
}
|
||||
|
||||
func (p *PaddedText) SetSize(x, y, _, _ int) {
|
||||
@ -396,6 +434,9 @@ func (p *PaddedText) Draw(s tcell.Screen) {
|
||||
if p.text == "" {
|
||||
return
|
||||
}
|
||||
if !p.visible {
|
||||
return
|
||||
}
|
||||
t := p.x
|
||||
s.SetContent(t, p.y, ' ', nil, p.style)
|
||||
t++
|
||||
@ -406,6 +447,10 @@ func (p *PaddedText) Draw(s tcell.Screen) {
|
||||
s.SetContent(t, p.y, ' ', nil, p.style)
|
||||
}
|
||||
|
||||
func (p *PaddedText) SetVisible(b bool) {
|
||||
p.visible = b
|
||||
}
|
||||
|
||||
type KeyValue struct {
|
||||
x, y int
|
||||
h, w int
|
||||
@ -413,6 +458,7 @@ type KeyValue struct {
|
||||
value string
|
||||
separator string
|
||||
style tcell.Style
|
||||
visible bool
|
||||
}
|
||||
|
||||
func NewKeyValue(key, separator, value string) *KeyValue {
|
||||
@ -420,6 +466,7 @@ func NewKeyValue(key, separator, value string) *KeyValue {
|
||||
key: key,
|
||||
separator: separator,
|
||||
value: value,
|
||||
visible: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,6 +479,9 @@ func (p *KeyValue) SetStyle(s tcell.Style) {
|
||||
}
|
||||
|
||||
func (p *KeyValue) Draw(s tcell.Screen) {
|
||||
if !p.visible {
|
||||
return
|
||||
}
|
||||
for j, r := range p.key {
|
||||
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 {
|
||||
return p.value
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user