[GH-ISSUE #376] TreeView: method to wrap entries or get minimal width #279

Closed
opened 2026-03-04 01:03:34 +03:00 by kerem · 2 comments
Owner

Originally created by @problame on GitHub (Dec 10, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/376

I have a Flex with TreeView | DetailView.
The TreeView's entry titles have variable sizes unknown at the time the TreeView is added to the Flex.

I want to resize the TreeView to an ideal fixed width such that the entry titles are shown completely.

Flex.ResizeItem allows resizing, but there is no way to get the ideal width from TreeView, i.e., after it added all indents, etc.

What is the best way to accomplish this?

Originally created by @problame on GitHub (Dec 10, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/376 I have a `Flex` with `TreeView | DetailView`. The `TreeView`'s entry titles have variable sizes unknown at the time the TreeView is added to the `Flex`. I want to resize the `TreeView` to an **ideal fixed width** such that the entry titles are shown completely. `Flex.ResizeItem` allows resizing, but there is no way to get the ideal width from `TreeView`, i.e., after it added all indents, etc. What is the best way to accomplish this?
kerem closed this issue 2026-03-04 01:03:34 +03:00
Author
Owner

@rivo commented on GitHub (Dec 29, 2019):

The package currently does not provide methods to calculate such a width. tview's layout is top-down so you have to know yourself how much space you give each element in a Flex.

Probably the best way is to determine the depth of your item (times the number of characters tview adds per branch) plus the width of your text (using something like runewidth.StringWidth()). For multiple items, you'll need to use the maximum over these widths.

Let me know if this helps you in any way.

<!-- gh-comment-id:569508197 --> @rivo commented on GitHub (Dec 29, 2019): The package currently does not provide methods to calculate such a width. `tview`'s layout is top-down so you have to know yourself how much space you give each element in a `Flex`. Probably the best way is to determine the depth of your item (times the number of characters `tview` adds per branch) plus the width of your text (using something like [`runewidth.StringWidth()`](https://godoc.org/github.com/mattn/go-runewidth#StringWidth)). For multiple items, you'll need to use the maximum over these widths. Let me know if this helps you in any way.
Author
Owner

@rivo commented on GitHub (Feb 19, 2020):

Will reopen if this turns out not to be resolved.

<!-- gh-comment-id:588349791 --> @rivo commented on GitHub (Feb 19, 2020): Will reopen if this turns out not to be resolved.
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#279
No description provided.