Misterio77 / nix-colors

Modules and schemes to make theming with Nix awesome.
GNU General Public License v3.0
488 stars 42 forks source link

HSL feature in nix-colors #52

Open MOIS3Y opened 6 months ago

MOIS3Y commented 6 months ago

@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 commented 5 months ago

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.