[GH-ISSUE #194] List.GetRect() gives incorrect size #152

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

Originally created by @delaneyj on GitHub (Nov 25, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/194

list := tview.NewList().
  AddItem("Quit", "Press to exit", 'q', nil)
x, y, w, h := list.GetRect()
log.Printf("just quit: %d,%d %dx%d", x, y, w, h)

Shows just quit: 0,0 15x10. It appears 15 width and 10 height are defaults of box object and don't match actual rendered size of box (in this case 2 for the height)

Originally created by @delaneyj on GitHub (Nov 25, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/194 ```Go list := tview.NewList(). AddItem("Quit", "Press to exit", 'q', nil) x, y, w, h := list.GetRect() log.Printf("just quit: %d,%d %dx%d", x, y, w, h) ``` Shows `just quit: 0,0 15x10`. It appears 15 width and 10 height are defaults of box object and don't match actual rendered size of box (in this case 2 for the height)
kerem closed this issue 2026-03-04 01:02:26 +03:00
Author
Owner

@rivo commented on GitHub (Nov 26, 2018):

Yes, this is correct. When you call tview.NewList(), the list is created with its default size. If you call list.GetRect() immediately afterwards, as you do, you will receive that size.

There are some functions which modify a primitive's size, for example Application.SetRoot(list, true) or any of the layout classes (Flex, Grid). When you call list.GetRect() after it was modified by these functions, you will get a different size and it should be the size that you see on screen.

Let me know if this clarifies it.

<!-- gh-comment-id:441583963 --> @rivo commented on GitHub (Nov 26, 2018): Yes, this is correct. When you call `tview.NewList()`, the list is created with its default size. If you call `list.GetRect()` immediately afterwards, as you do, you will receive that size. There are some functions which modify a primitive's size, for example `Application.SetRoot(list, true)` or any of the layout classes (`Flex`, `Grid`). When you call `list.GetRect()` after it was modified by these functions, you will get a different size and it should be the size that you see on screen. Let me know if this clarifies it.
Author
Owner

@delaneyj commented on GitHub (Nov 26, 2018):

Well I'm using a List inside a Flex but the Rect is still 15x10. I would think when you add an item the Rect would get recalculated/updated. Basically when you add to a Flex you have to give it a height, and that height is wrong.

<!-- gh-comment-id:441716135 --> @delaneyj commented on GitHub (Nov 26, 2018): Well I'm using a List inside a Flex but the Rect is still 15x10. I would think when you add an item the `Rect` would get recalculated/updated. Basically when you add to a Flex you have to give it a height, and that height is wrong.
Author
Owner

@rivo commented on GitHub (Dec 3, 2018):

It gets updated when it's drawn, not when it's added. Because the actual screen size is known only at drawing time and most primitives such as Flex depend on the actual screen size. Thus, the final positions and sizes of primitives get calculated only when they are drawn.

Maybe you want to let me know where this gives you problems so I can suggest a solution.

<!-- gh-comment-id:443658564 --> @rivo commented on GitHub (Dec 3, 2018): It gets updated when it's drawn, not when it's added. Because the actual screen size is known only at drawing time and most primitives such as `Flex` depend on the actual screen size. Thus, the final positions and sizes of primitives get calculated only when they are drawn. Maybe you want to let me know where this gives you problems so I can suggest a solution.
Author
Owner

@rivo commented on GitHub (Dec 14, 2018):

Will reopen when there's new information that requires action.

<!-- gh-comment-id:447371876 --> @rivo commented on GitHub (Dec 14, 2018): Will reopen when there's new information that requires action.
Author
Owner

@rivo commented on GitHub (Feb 16, 2022):

There was another comment here which I can't see anymore. Please comment/reopen/open a new issue if there's anything I should look at.

<!-- gh-comment-id:1041864263 --> @rivo commented on GitHub (Feb 16, 2022): There was another comment here which I can't see anymore. Please comment/reopen/open a new issue if there's anything I should look at.
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#152
No description provided.