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

HSL feature in nix-colors #52

Open
MOIS3Y opened this issue Mar 24, 2024 · 1 comment
Open

HSL feature in nix-colors #52

MOIS3Y opened this issue Mar 24, 2024 · 1 comment

Comments

@MOIS3Y
Copy link

MOIS3Y commented Mar 24, 2024

@Misterio77 hi and thank you so much for the nix-colors, it’s amazing)

I was making a library to use base16 in Qtile, my main goal was to use only base16.
But sometimes there really aren’t enough colors, so I wrote a small class that receives a base16 color as input and shifts it according to HSL.
hslpicker

This is what it looks like:

Alt text

This is result:

  #...
 from base16_colorlib import Color
 from base16_colorlib import catppuccin_mocha
 #...

 colors = Color(**catppuccin_mocha)

 #...
 widgets = {
     #...
     'Timelabel': widget.TextBox(
         background=colors.lightness(colors.scheme['base0D'], -4),  # <= look this
         foreground=colors.scheme['base00'],
        #...
     ),
     'Time': widget.Clock(
         background=colors.scheme['base0D'],  # <= look this
         foreground=colors.scheme['base00'],
         #...
     ),
     #...
 }

Alt text

I saw some math in the nix-colors source code)
Maybe try implementing lib functions for nix-color that could allow changing colors in the configuration?

The shift is universal for all color schemes.
If, as in the example above, you need one color to be slightly darker or more saturated than another, this will work with any theme switched on the fly, etc.

For example, I rewrote the implementation from python to lua for awesomewm.
colorize
The difficulty with math is mainly in the functions for converting hex-rgb-hsl-rgb-hex, otherwise everything is elementary.
But as for Nix, unfortunately I don't know nixpkgs.lib well and can only write simple nix expressions(

I know that nix is ​​primarily a package manager, but it is also a functional language)

@AndrewKvalheim
Copy link

I had a similar need and implemented conversion from OKLCH. Without NixOS/nix#10387 it’s a bit rough, but you might find it useful.

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

No branches or pull requests

2 participants