bubbles icon indicating copy to clipboard operation
bubbles copied to clipboard

feat(table): expose `start` and `end` fields via getter methods

Open pyrooka opened this issue 1 year ago • 3 comments

This PR exposes the start and the end fields from the table model struct.

Not having setters is fine because that would break the inner logic, but handling mouse clicks on rows is a bit inconvenient because the mouse events contain the relative position but to select the actual row under the (mouse)cursor, the absolute row index is needed. With exporting these - mainly the start - it should be as easy as table.Start() + mouseMsg.Y.

pyrooka avatar Aug 01 '23 15:08 pyrooka

Can someone review this? I don't want to bother maintainers by tagging. :)

pyrooka avatar Sep 27 '23 10:09 pyrooka

Hi, there. Just curious, what your use case for this?

meowgorithm avatar Sep 27 '23 13:09 meowgorithm

I'm working on a TUI app which has to support mouse clicks. Currently - when the content is scrolled - there is no way to get the offset of the first rendered row. Only the selected row is available (under the cursor), but that's not what I'd like to get. I've made a small hack which works, but it's definitely not ideal :)

rowOffset := int(reflect.ValueOf(&m.tableData.table).Elem().FieldByName("start").Int())

pyrooka avatar Sep 27 '23 13:09 pyrooka

Hey @pyrooka, thank you for the PR. We're working on swapping out the implementation of the Bubble Table with using Lip Gloss tables:

https://github.com/charmbracelet/lipgloss/releases/tag/v0.9.0

That being said, we'll want to make sure the API is as small as possible so we limit breaking changes as much as possible. I will close this PR for now but we can revisit after we introduce Lip Gloss tables as the rendering for the bubble.

maaslalani avatar Mar 13 '24 18:03 maaslalani

I see, thanks for the update! I'll keep my on the transition as we might need to change our code, since we use unexported fields via reflection. :)

pyrooka avatar Mar 13 '24 21:03 pyrooka