[GH-ISSUE #231] Grid questions #177

Closed
opened 2026-03-04 01:02:39 +03:00 by kerem · 8 comments
Owner

Originally created by @dguendisch on GitHub (Jan 22, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/231

I have a hard time understanding Grid's meaning of width and height. Either the code documentation is mixing them up a lot (not likely) or I have a different understanding than tview about them (more likely).
Let's take e.g. the doc of its AddItem(p Primitive, row int, column int, height int, width int, ...) method:

The top-left corner of the primitive will be located in the top-left corner of the grid cell at the given row and column and will span "width" rows and "height" columns.

How can something span a width of rows?? I mean the wider an item gets, the more columns it spans.
The same for "... span ... height columns": the higher an item gets, the more rows it will span.

Later:

For example, for a primitive to occupy rows 2, 3, and 4 and columns 5 and 6:
grid.AddItem(p, 2, 4, 3, 2, true)

Ok, so we add p at row=2 with a height=3, so it'll span row 2, 3 and 4 => I understand that one, it matches my understanding of width and height :)
But we define col=4 and width=2, so it should span columns 4 and 5 instead of what's written in the documentation.

The same goes on with SetRows(...)...

But I guess I got something totally wrong with the Grid, so any explanation is appreciated :)

Originally created by @dguendisch on GitHub (Jan 22, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/231 I have a hard time understanding `Grid`'s meaning of width and height. Either the code documentation is mixing them up a lot (not likely) or I have a different understanding than tview about them (more likely). Let's take e.g. the doc of its `AddItem(p Primitive, row int, column int, height int, width int, ...)` method: > The top-left corner of the primitive will be located in the top-left corner of the grid cell at the given row and column and will span "width" rows and "height" columns. How can something span a width of rows?? I mean the _wider_ an item gets, the more **columns** it spans. The same for "... span ... height columns": the _higher_ an item gets, the more **rows** it will span. Later: > For example, for a primitive to occupy rows 2, 3, and 4 and columns 5 and 6: grid.AddItem(p, 2, 4, 3, 2, true) Ok, so we add `p` at row=2 with a height=3, so it'll span row 2, 3 and 4 => I understand that one, it matches my understanding of width and height :) But we define col=4 and width=2, so it should span columns 4 and 5 instead of what's written in the documentation. The same goes on with `SetRows(...)`... But I guess I got something totally wrong with the `Grid`, so any explanation is appreciated :)
kerem closed this issue 2026-03-04 01:02:39 +03:00
Author
Owner

@rivo commented on GitHub (Jan 22, 2019):

I renamed the parameters in AddItem() to colSpan and rowSpan. I also fixed the example which, as you pointed out, was wrong. I believe this should clarify your questions.

If you're still having trouble with this, let me know.

<!-- gh-comment-id:456529694 --> @rivo commented on GitHub (Jan 22, 2019): I renamed the parameters in `AddItem()` to `colSpan` and `rowSpan`. I also fixed the example which, as you pointed out, was wrong. I believe this should clarify your questions. If you're still having trouble with this, let me know.
Author
Owner

@dguendisch commented on GitHub (Jan 22, 2019):

The names are more clearer, thanks. As I see from 1ac6fbc the doc was indeed wrong. E.g. in the doc width was replaced with rowSpan, while in the method signature, height was replaced with rowSpan, so the doc mixed it up.

If you like to continue, see e.g. SetRows doc. I understand what it does but the doc states e.g.

Each value defines the size of one row, starting with the leftmost row.

There is in my understanding no such thing as a "leftmost row", there is either a "topmost row" or a "leftmost column". It continues then with mixing width and height in the same way as in AddItem previously. Really confusing for newbies like me :)

<!-- gh-comment-id:456533480 --> @dguendisch commented on GitHub (Jan 22, 2019): The names are more clearer, thanks. As I see from 1ac6fbc the doc was indeed wrong. E.g. in the doc `width` was replaced with `rowSpan`, while in the method signature, `height` was replaced with `rowSpan`, so the doc mixed it up. If you like to continue, see e.g. [`SetRows` doc](https://github.com/rivo/tview/blob/master/grid.go#L78). I understand what it does but the doc states e.g. > Each value defines the size of one row, starting with the leftmost row. There is in my understanding no such thing as a "leftmost row", there is either a "topmost row" or a "leftmost column". It continues then with mixing width and height in the same way as in `AddItem` previously. Really confusing for newbies like me :)
Author
Owner

@rivo commented on GitHub (Jan 24, 2019):

Thanks for catching this one, too. I think I must have switched SetColumns() with SetRows() at some point without fully adapting the comments. My latest commit should fix those comments.

Let me know if you find anything else.

<!-- gh-comment-id:457173083 --> @rivo commented on GitHub (Jan 24, 2019): Thanks for catching this one, too. I think I must have switched `SetColumns()` with `SetRows()` at some point without fully adapting the comments. My latest commit should fix those comments. Let me know if you find anything else.
Author
Owner

@dguendisch commented on GitHub (Jan 24, 2019):

Thanks a lot, now everything makes sense :)

<!-- gh-comment-id:457236723 --> @dguendisch commented on GitHub (Jan 24, 2019): Thanks a lot, now everything makes sense :)
Author
Owner

@xhsky commented on GitHub (Jun 24, 2022):

The row and columns of the grid's AddItem() seem to be a ratio, not the row and width on the screen? Are there more detailed descriptions and examples of these parameters?

<!-- gh-comment-id:1165271429 --> @xhsky commented on GitHub (Jun 24, 2022): The row and columns of the grid's AddItem() seem to be a ratio, not the row and width on the screen? Are there more detailed descriptions and examples of these parameters?
Author
Owner

@rivo commented on GitHub (Jun 24, 2022):

The rowSpan and columnSpan parameters refer to rows and columns of the grid, not the screen. The size of the grid's rows and columns are defined with SetColumns() and SetRows(). See SetColumns() for a detailed description, including proportional sizing.

<!-- gh-comment-id:1165277245 --> @rivo commented on GitHub (Jun 24, 2022): The `rowSpan` and `columnSpan` parameters refer to rows and columns of the grid, not the screen. The size of the grid's rows and columns are defined with `SetColumns()` and `SetRows()`. See [`SetColumns()`](https://pkg.go.dev/github.com/rivo/tview#Grid.SetColumns) for a detailed description, including proportional sizing.
Author
Owner

@xhsky commented on GitHub (Jun 24, 2022):

The rowSpan and columnSpan parameters refer to rows and columns of the grid, not the screen. The size of the grid's rows and columns are defined with SetColumns() and SetRows(). See SetColumns() for a detailed description, including proportional sizing.

func (g *Grid) AddItem(p Primitive, row, column, rowSpan, colSpan, minGridHeight, minGridWidth int, focus bool) *Grid
Do the row and column in this function parameter represent the starting position of p on the screen? How exactly is it positioned?

<!-- gh-comment-id:1165314926 --> @xhsky commented on GitHub (Jun 24, 2022): > The `rowSpan` and `columnSpan` parameters refer to rows and columns of the grid, not the screen. The size of the grid's rows and columns are defined with `SetColumns()` and `SetRows()`. See [`SetColumns()`](https://pkg.go.dev/github.com/rivo/tview#Grid.SetColumns) for a detailed description, including proportional sizing. func (g *Grid) AddItem(p Primitive, row, column, rowSpan, colSpan, minGridHeight, minGridWidth int, focus bool) *Grid Do the row and column in this function parameter represent the starting position of p on the screen? How exactly is it positioned?
Author
Owner

@rivo commented on GitHub (Jun 24, 2022):

Pretty much like the documentation says:

The top-left corner of the primitive will be located in the top-left corner of the grid cell at the given row and column and will span "rowSpan" rows and "colSpan" columns.

Grid rows and grid columns, that is.

<!-- gh-comment-id:1165584296 --> @rivo commented on GitHub (Jun 24, 2022): Pretty much like [the documentation](https://pkg.go.dev/github.com/rivo/tview#Grid.AddItem) says: > The top-left corner of the primitive will be located in the top-left corner of the grid cell at the given row and column and will span "rowSpan" rows and "colSpan" columns. _Grid_ rows and _grid_ columns, that is.
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#177
No description provided.