[GH-ISSUE #850] padding getting ignored #620

Closed
opened 2026-03-04 01:06:30 +03:00 by kerem · 1 comment
Owner

Originally created by @tcurdt on GitHub (May 20, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/850

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?

Originally created by @tcurdt on GitHub (May 20, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/850 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?
kerem closed this issue 2026-03-04 01:06:30 +03:00
Author
Owner

@rivo commented on GitHub (Jun 18, 2023):

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).

<!-- gh-comment-id:1596243035 --> @rivo commented on GitHub (Jun 18, 2023): 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).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#620
No description provided.