[GH-ISSUE #277] Resolve Grid's preference of larger items #216

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

Originally created by @Anaminus on GitHub (Apr 25, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/277

The following code is meant to demonstrate a primitive p that either fills the screen, or is centered when the screen is wide enough:

grid := tview.NewGrid()
grid.SetSize(3, 3, 0, 0)
grid.AddItem(p, 0, 0, 3, 3, 0, 0, true)   //  <100: fullscreen
grid.AddItem(p, 1, 1, 1, 1, 0, 100, true) // >=100: centered

In practice, the primitive is always drawn fullscreen, because the grid prefers the larger of the two items. Since priority is otherwise determined by insertion order, this preference seems to do very little other than restrict the layouts that are possible with grids. Unfortunately, outright removing the behavior isn't backwards-compatible, so I suggest making it optional with some sort of set-size-preference method.

If a breaking change is tolerable, then the issue could be resolved by removing the following lines:

github.com/rivo/tview@90b4da1bd6/grid.go (L319-L322)

Originally created by @Anaminus on GitHub (Apr 25, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/277 The following code is meant to demonstrate a primitive `p` that either fills the screen, or is centered when the screen is wide enough: ```go grid := tview.NewGrid() grid.SetSize(3, 3, 0, 0) grid.AddItem(p, 0, 0, 3, 3, 0, 0, true) // <100: fullscreen grid.AddItem(p, 1, 1, 1, 1, 0, 100, true) // >=100: centered ``` In practice, the primitive is always drawn fullscreen, because the grid prefers the larger of the two items. Since priority is otherwise determined by insertion order, this preference seems to do very little other than restrict the layouts that are possible with grids. Unfortunately, outright removing the behavior isn't backwards-compatible, so I suggest making it optional with some sort of set-size-preference method. If a breaking change is tolerable, then the issue could be resolved by removing the following lines: https://github.com/rivo/tview/blob/90b4da1bd64ceee13d2e7d782b315b819190f7bf/grid.go#L319-L322
kerem closed this issue 2026-03-04 01:03:03 +03:00
Author
Owner

@rivo commented on GitHub (May 14, 2019):

This was actually a bug, it turns out. The comments for Grid.AddItem() say:

If multiple items for the same primitive apply, the one that has at least one highest minimum value will be used, or the primitive added last if those values are the same.

The code you showed compared the item's width/height instead of the minimum width/height. I fixed this in the latest commit.

<!-- gh-comment-id:492305725 --> @rivo commented on GitHub (May 14, 2019): This was actually a bug, it turns out. The comments for [`Grid.AddItem()`](https://godoc.org/github.com/rivo/tview#Grid.AddItem) say: > If multiple items for the same primitive apply, the one that has at least one highest **minimum** value will be used, or the primitive added last if those values are the same. The code you showed compared the item's width/height instead of the minimum width/height. I fixed this in the latest commit.
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#216
No description provided.