Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dlvhdr opened this issue Sep 15, 2024 · 3 comments
Open

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

dlvhdr opened this issue Sep 15, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@dlvhdr
Copy link

dlvhdr commented Sep 15, 2024

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

@dlvhdr dlvhdr added the enhancement New feature or request label Sep 15, 2024
@caarlos0
Copy link
Member

caarlos0 commented Oct 9, 2024

hey Dolev!

I think the Offset() method makes sense.

Do you wanna work on a PR, or should I do it?

@caarlos0 caarlos0 self-assigned this Oct 9, 2024
@dlvhdr
Copy link
Author

dlvhdr commented Oct 9, 2024

I was actually thinking of taking a stab at writing a bubbles for the tree, so I'm thinking maybe I can write a draft to figure out if anything else needs to be exposed before implementing Offset, wdyt?

@caarlos0
Copy link
Member

caarlos0 commented Oct 9, 2024

Awesome! Sounds like a plan 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants