[GH-ISSUE #1033] SetBackgroundColor doesn't work on Box #750

Open
opened 2026-03-04 01:07:28 +03:00 by kerem · 1 comment
Owner

Originally created by @ardawan on GitHub (Oct 10, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/1033

I'm not sure if this is a bug or I'm not familiar with this package.
Understand that each Flex type has a *Box as mentioned in the doc.

type Flex struct {
	*Box

	// The items to be positioned.
	items []*flexItem

	// FlexRow or FlexColumn.
	direction int

	// If set to true, Flex will use the entire screen as its available space
	// instead its box dimensions.
	fullScreen bool
}

But when I try to set the background color for the box, nothing will change.

f := tview.NewFlex().SetDirection(tview.FlexRow)
f.Box.SetBackgroundColor(tcell.ColorGreen)

So the question is how can we set a background color for the whole flex primitive?

Originally created by @ardawan on GitHub (Oct 10, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/1033 I'm not sure if this is a bug or I'm not familiar with this package. Understand that each `Flex` type has a `*Box` as mentioned in the doc. ```golang type Flex struct { *Box // The items to be positioned. items []*flexItem // FlexRow or FlexColumn. direction int // If set to true, Flex will use the entire screen as its available space // instead its box dimensions. fullScreen bool } ``` But when I try to set the background color for the box, nothing will change. ```golang f := tview.NewFlex().SetDirection(tview.FlexRow) f.Box.SetBackgroundColor(tcell.ColorGreen) ``` So the question is how can we set a background color for the whole flex primitive?
Author
Owner

@rivo commented on GitHub (Oct 16, 2024):

Container primitives such as Flex or Grid don't clear the screen they occupy. So the background colour is ignored. One of the reasons is that they are used to position other elements on the screen. See for example the Wiki: https://github.com/rivo/tview/wiki/Modal

<!-- gh-comment-id:2417816665 --> @rivo commented on GitHub (Oct 16, 2024): Container primitives such as `Flex` or `Grid` don't clear the screen they occupy. So the background colour is ignored. One of the reasons is that they are used to position other elements on the screen. See for example the Wiki: https://github.com/rivo/tview/wiki/Modal
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#750
No description provided.