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

Add Alternating Colors for Help Table #466

Merged
merged 10 commits into from
Jul 2, 2024

Conversation

przb
Copy link
Contributor

@przb przb commented Jun 13, 2024

I started using spotify-player, and I found the help table difficult to read. I added alternating row coloring as pictured below to help with identifying keybindings.

image

@przb przb marked this pull request as ready for review June 13, 2024 22:52
Copy link
Owner

@aome510 aome510 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Can you make this configurable for both the alternative behaviour and the color?

Row::new(vec![
Cell::from(format!("{command:?}")),
Cell::from(format!("[{keys}]")),
Cell::from(command.desc()),
])
// adding alternating row colors
.style(if (i + scroll_offset) % 2 == 0 {
ui.theme.app().bg(Color::DarkGray)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have a particular style in mind? Almost seems to me like having a new alternate row field for the ComponentStyle struct could work.

Copy link
Owner

@aome510 aome510 Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think you could add new component style named help_table_alternating_row for example. DarkGray background might be a good start. You can also try different modifiers; I'm not sure how nice they will look. It's to allow people with incompatible theme to update the style.

Copy link
Contributor Author

@przb przb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs have not been updated yet. Is that manually updated, or should I update it?

@@ -74,6 +77,7 @@ pub struct ComponentStyle {
pub playlist_desc: Option<Style>,
pub table_header: Option<Style>,
pub selection: Option<Style>,
pub secondary_row: Option<Style>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I named this secondary row because I thought it could be used in more places than just the help table, but let me know if it should just be for the help table.

@@ -58,6 +58,9 @@ pub struct Palette {
pub bright_blue: Color,
#[serde(default = "Color::bright_yellow")]
pub bright_yellow: Color,

#[serde(default = "Color::dark_gray")]
pub dark_gray: Color,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added support for dark gray coloring, but is there a better way to add support for coloring modifications? Dark and Bright colors seem to have some repetition. And should other dark colors be added as well?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you shouldn't add new field to the palette, it represents the basic 16-color palette with additional fields for background and foreground.

pub fn secondary_row(&self) -> tui::style::Style {
match &self.component_style.secondary_row {
None => Style::default()
.bg(StyleColor::DarkGray)
Copy link
Owner

@aome510 aome510 Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use StyleColor::Rgb instead if you want a specific color that is not available in the palette. My suggestion would be using default theme if None, so it doesn't cause any surprise for current users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but this enables the alternating row colors by default, right? I was thinking that should be the intended behavior; should it instead only set alternating row colors when using a custom theme?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that should be the intended behavior; should it instead only set alternating row colors when using a custom theme?

Yeah, it should be opt-in. My reasoning is that setting to some default style (e.g dark gray as above) might "break" some users' theme. If one wants the alternating colors, they can update the style in their configs.

@@ -42,6 +42,31 @@ bright_magenta = "#ff79c6"
bright_cyan = "#8be9fd"
bright_white = "#ffffff"

[[themes]]
name = "my_dracula"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you name it dracula2 or something? Can also add a small comment explaining the difference between this and the previous dracula

@aome510 aome510 merged commit 95f0edf into aome510:master Jul 2, 2024
3 checks passed
@apprehensions
Copy link
Contributor

Why not introduce this to the music page as well?

@aome510
Copy link
Owner

aome510 commented Jul 4, 2024

Why not introduce this to the music page as well?

Do you mean track table? Should be easy to add tho

juliamertz pushed a commit to juliamertz/spotify-player that referenced this pull request Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants