rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.12k stars 576 forks source link

Adding a border removes the content of the element #957

Closed justlunix closed 8 months ago

justlunix commented 8 months ago

Hi, I have a problem where when I set the border on an element, the content won't be displayed anymore. I'm probably doing something wrong, so maybe someone can help me.

I think it's because the SetBorder returns a Box, so it "forgets" the other non-box settings. But I don't know how to fix it.

func Welcome() tview.Primitive {
    return tview.NewFlex().
        AddItem(nil, 0, 1, false).
        AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
            AddItem(nil, 0, 1, false).
            AddItem(connectionList(), 0, 1, false).
            AddItem(nil, 0, 1, false), 0, 2, false).
        AddItem(nil, 0, 1, false)
}

func hasConnections() bool {
    return true
}

func connectionList() tview.Primitive {
    if hasConnections() {
        return tview.NewList().
            AddItem("List item 1", "Some explanatory text", 'a', nil).
            AddItem("List item 2", "Some explanatory text", 'b', nil).
            AddItem("List item 3", "Some explanatory text", 'c', nil).
            AddItem("List item 4", "Some explanatory text", 'd', nil).
            AddItem("Quit", "Press to exit", 'q', nil).
            SetBorder(true).
            SetTitle("Connections")

    } else {
        return tview.NewTextView().
            SetText("No connections found. Press 'a' to add a connection.").
            SetBorder(true).
            SetTitle("Connections")
    }
}

This will result in:

image

If I remove the border it will display like this:

if hasConnections() {
        return tview.NewList().
            AddItem("List item 1", "Some explanatory text", 'a', nil).
            AddItem("List item 2", "Some explanatory text", 'b', nil).
            AddItem("List item 3", "Some explanatory text", 'c', nil).
            AddItem("List item 4", "Some explanatory text", 'd', nil).
            AddItem("Quit", "Press to exit", 'q', nil)
    }
image
justlunix commented 8 months ago

Well, I knew it was something simple. Of course I need to call the methods without actually replacing the variable by the returned struct. :)

list := tview.NewList().
    AddItem("List item 1", "Some explanatory text", 'a', nil).
    AddItem("List item 2", "Some explanatory text", 'b', nil).
    AddItem("List item 3", "Some explanatory text", 'c', nil).
    AddItem("List item 4", "Some explanatory text", 'd', nil).
    AddItem("Quit", "Press to exit", 'q', nil)

list.SetBorder(true).
    SetTitle("Connections")

return list