Add a Hash property transform to color content from a palette - #1065
Add a Hash property transform to color content from a palette#1065ChrisJr404 wants to merge 1 commit into
Hash property transform to color content from a palette#1065Conversation
mierak
left a comment
There was a problem hiding this comment.
Thanks!
Documentation is needed before this can be merged too.
| /// The same content always maps to the same color, while different content is | ||
| /// spread across the palette. Returns `None` when `colors` is empty so callers | ||
| /// can leave the content unstyled. | ||
| pub(crate) fn hashed_color(content: &str, colors: &[Color]) -> Option<Color> { |
There was a problem hiding this comment.
This should live in the ui module not the config since its used during the application's lifecycle and not on startup.
| content: Box<PropertyFile<T>>, | ||
| replacements: Vec<ReplacementFile<T>>, | ||
| }, | ||
| Hash { |
There was a problem hiding this comment.
The name Hash does not really describe the behavior at all. Something like Colorize/Palette/PaletteColor or something similar would be better.
| }, | ||
| Hash { | ||
| content: Box<PropertyFile<T>>, | ||
| colors: Vec<String>, |
There was a problem hiding this comment.
This should be a whole Style instead of a simple fg color. Gives more freedom to users and lets them avoid contrast issues.
The new `Hash` transform renders its content and picks a foreground color from a configured palette based on a stable hash of the resulting text, so the same value (an artist, year, album, ...) always gets the same color while different values are spread across the palette. It follows the existing `Truncate`/`Replace` transforms: it wraps a `content` property, takes a `colors` list, and plugs into the same config conversion and string/span/line rendering paths.
0261fd3 to
2f2e588
Compare
|
Rebased onto master to clear the conflict. Docs live in the separate site repo now, so I added the Hash transform to the Transforms table there in rmpc-org/rmpc-org.github.io#75. Thanks! |
|
What about the other points? |
|
Hi, are you still going to finish this? |
|
Yes, still on it, sorry for the delay. I agree with all three points: I will move it into the ui module since it runs during the application lifecycle rather than at startup, rename it to something that describes the behavior (Palette or Colorize rather than Hash), and take a full Style instead of just a foreground color so users can avoid contrast issues. I will push the revision. |
Closes #839.
What
Adds a new
Hashproperty transform. It renders itscontentand applies a foreground color chosen from a configuredcolorspalette based on a stable hash of the rendered text. The same value always maps to the same color while different values spread across the palette, which makes it easy to tell artists, years or albums apart at a glance in a list view.How
It mirrors the existing
Truncate/Replacetransforms:Hashvariant on bothTransformFile(config) andTransform(runtime); the palette strings are parsed intoratatuicolors once, during config conversion, in bothproperties.rsandqueue_table.rs;panes/mod.rs,song_ext.rs). The string path returns the content unchanged; the span and line paths override the foreground with the hashed color and leave the rest of the style intact.The color is selected with a small FNV-1a hash so the mapping is stable across runs and platforms. An empty palette is a no-op (the content stays unstyled), so it degrades gracefully.
Tests
as_spantests for content pass-through, deterministic coloring from the palette, and the empty-palette no-op.cargo test,cargo fmt(nightly) andcargo clippyare all clean.