Skip to content

tree - expose node offset to make styling based on it possible #365

Open
@dlvhdr

Description

@dlvhdr

Is your feature request related to a problem? Please describe.

I would like to limit the width of a node's text so it's always one line.

Also, I'm not sure if it's possible, but I would like to have the ability to add ellipsis to items with overflowing text - could be a separate issue.

Describe the solution you'd like

Expose an offset attribute so I know what level a node is in (its depth).
I will then use it like so:

tree.Root().ItemStyleFunc(func(children tree.Children, i int) lipgloss.Style {
  node := children.At(i)
  return lipgloss.NewStyle().MaxWidth(SidebarWidth - node.Offset())
})

Describe alternatives you've considered

  • Using MaxHeight(1) inside ItemStyleFunc is not enough since the text overflows to the next line.
  • Using MaxWidth() inside ItemStyleFunc works but I can't know what width to put it since I don't know the offset and therefor how much room I have.

Additional context
Using MaxWidth of 10 gives me this which only "works" for some of the nodes.
image

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions