rivo / tview

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

padding getting ignored #850

Closed tcurdt closed 1 year ago

tcurdt commented 1 year ago

I am trying to create a horizontal flex but want to control the spacing between the components.

    d := tview.NewDropDown()
    d.SetFieldWidth(40)
    //d.SetBorderPadding(0, 0, 0, 1)

    a := tview.NewButton("1")
    //a.SetBorderPadding(0, 0, 1, 0)

    b := tview.NewButton("2")
    //b.SetBorderPadding(0, 0, 1, 0)

    layout := tview.NewFlex().
        SetDirection(tview.FlexColumn).
        AddItem(d, 0, 1, false).
        AddItem(a, 3, 0, false).
        AddItem(b, 3, 0, false)

This results in the following: ddddddddddda1ab2b but want I want is: ddddddddd a1a b2b

I have experimented with with the flex item width and the various paddings but I somehow must be missing something.

What I ended up doing:

    layout := tview.NewFlex().
        SetDirection(tview.FlexColumn).
        AddItem(d, 0, 1, false).
        AddItem(nil, 1, 0, false).
        AddItem(a, 3, 0, false).
        AddItem(nil, 1, 0, false).
        AddItem(b, 3, 0, false)

Is that a horrible workaround or the intend way of using the API?

rivo commented 1 year ago

No, this is not a horrible workaround. Flex doesn't have a built-in way to add spacing between items. So adding a nil item is perfectly fine and it will give you precise control over how much spacing you want to add.

Alternatively, you could use Grid with one row and define extra columns where you don't place any elements.

The "border padding" you tried to add before only affects the inside of a primitive. It's the space between the primitive's content and its border (if there is one).