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

Feature request: Style table rows / cells individually #246

Open
SkyLeite opened this issue Sep 17, 2022 · 7 comments · May be fixed by #617
Open

Feature request: Style table rows / cells individually #246

SkyLeite opened this issue Sep 17, 2022 · 7 comments · May be fixed by #617
Assignees
Labels
enhancement New feature or request

Comments

@SkyLeite
Copy link

I would like to be able to provide styling for rows and / or cells individually. Currently the only way to do this is through the Selected property, but that approach is limited in the sense that you can only have two styles (one for the base, and one for the selected row).

@maaslalani
Copy link
Contributor

Hey, this is a good idea and natural extension of the table. I think we should probably introduce a row that can take any struct that implements the Stringer interface so that you can pass lipgloss Styles and anything else for displaying the table.

@muesli muesli added the enhancement New feature or request label Oct 5, 2022
@pja237
Copy link

pja237 commented Feb 24, 2023

Hey all,
@maaslalani this is my attempt at this feature, goal for me was:

  1. be backward compatible, all the code using the table package continues to work as-is
  2. not have to change too much of the table.go code (which tbh. i don't know how to achieve by changing the Row to an interface, i end up having to refactor half of the package, or break no 1. and do ton of code changes in the existing app 😆 )

and this is the best i could come up with, if you'd be interested to take a look and let me know what you think of this approach (it's a local, older copy of tables code i'm still using, but i can easily PR this here)

  1. i've composed a new CustomStyles struct in the table model
    https://github.com/CLIP-HPC/SlurmCommander/blob/alt_table_2/internal/table/table.go#L22

which holds interfaces for Cell/Row/Selected functions.

// int is the row/col number, row is the row content, used in the methods to generate custom styles
type CustomStyle interface {
	Style(int, Row) lipgloss.Style
}

https://github.com/CLIP-HPC/SlurmCommander/blob/alt_table_2/internal/table/table.go#L28-L32

  1. modified the renderRow() method to include checks if functions are present in the model and do the "overlaying" of cell<-row<-selected styles (using .Inherit()) so we can compose them.
    https://github.com/CLIP-HPC/SlurmCommander/blob/alt_table_2/internal/table/table.go#L406-L454

This way, separate styles for a single Cell/Column of cells/Row/Selected rows can be programmatically done, like i'm doing here (first working prototype):
https://github.com/CLIP-HPC/SlurmCommander/blob/alt_table_2/internal/model/tabs/clustertab/clustertabtable.go#L69-L90

Screenshot 2023-02-24 at 20 46 53

@jlec
Copy link

jlec commented Feb 27, 2023

@pja237 Could you create a PR so that we can work together on refining your idea?

@pja237
Copy link

pja237 commented Feb 27, 2023

@jlec Was hoping someone would be willing to help me with this 👍
I've done the PR, it's above. Looking forward to hearing your thoughts.

@hedhyw
Copy link

hedhyw commented Jul 23, 2023

I've implemented the first part for stylizing cells: #397
Please, review.

@fsareshwala
Copy link

fsareshwala commented Jul 23, 2023

I've implemented the first part for stylizing cells: #397
Please, review.

Code looks good to me. I've personally been waiting for this for a personal project of mine so I'm excited to have this merged.

@bashbunni
Copy link
Member

Hey this was introduced in #504 and will be in the next release :)

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

Successfully merging a pull request may close this issue.

8 participants