bubbles icon indicating copy to clipboard operation
bubbles copied to clipboard

fix(table): substract headers Y size from the total table size

Open prgres opened this issue 2 years ago • 4 comments

I spotted a bug while creating a table and viewport side by side. Even though they have set the exact height value, both have different sizes. While debugging, it came out that we only passed it down to the nested viewport component by setting table height, but the render method looks like this.

// View renders the component.
func (m Model) View() string {
	return m.headersView() + "\n" + m.viewport.View()
}

So, the total height of the table is the sum of the viewport's height and the headers' height. I have simply subtracted headings Y size from the viewport height, and it looks like this fixed the issue.

prgres avatar Nov 13 '23 13:11 prgres

Okay, it does not work as I expected. I will dig it up latter

prgres avatar Nov 13 '23 14:11 prgres

Okay, first of all, I changed GetFrameSize to GetVerticalFrameSize since X calculations are not helpful here.

Secondly, I realized that GetVerticalFrameSize does not return the total height of the component - just the sum of margins, padding, and borders. So, besides subtracting that one bad boi, I have to get in content height. I have used lipgloss.Height(m.headersView()) in the SetHeight function. I am unsure if this approach is good since it renders it twice (in SetHeight and View functions).

What is worth mentioning is that the content height, with the current implementation, is always 0 or 1 due to truncating the header text. But I keep in mind that if https://github.com/charmbracelet/bubbles/pull/433 will merge, I would also like to make a similar one for that part. That's why I decided to calculate that value here.

prgres avatar Nov 13 '23 14:11 prgres

Update once again:

During testing on a local setup, it came out that GetVerticalFrameSize is not necessary at all. But would great if somebody could confirm that

prgres avatar Nov 13 '23 17:11 prgres

@meowgorithm @muesli i do not who to ping

prgres avatar Nov 27 '23 09:11 prgres

Hey @prgres, thanks so much for the PR ❤️

maaslalani avatar Feb 28 '24 17:02 maaslalani

Thanks for the PR @prgres, I merged this one since it's a simple bug fix but just to give you a heads up, we're going to swap out the entire implementation for the Lip Gloss table renderer:

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

maaslalani avatar Mar 13 '24 18:03 maaslalani