stylix: add config.lib.stylix.{mkHexColor,mkOpacityHexColor} functions

Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
eveeifyeve 2025-05-15 22:30:56 +10:00 committed by NAHO
parent 9991299fe9
commit 1a83d26d4c
No known key found for this signature in database
GPG key ID: BFB5D5E3F4C95185
6 changed files with 29 additions and 0 deletions

View file

@ -182,6 +182,15 @@ individually.
Also note that reading generated files with `builtins.readFile` can be very slow
and should be avoided.
### Hexadecimal colors
- config.lib.stylix.mkHexColor`: Converts a hex `color` (e.g., `RRGGBB` or
`#RRGGBB`) to `0xRRGGBB`.
- `config.lib.stylix.mkOpacityHexColor`: Converts a hex `color` and `opacity`
(01) to `0xRRGGBBAA`.
## How to apply other things
For everything else, like fonts and wallpapers, you can just take option values

16
stylix/colors.nix Normal file
View file

@ -0,0 +1,16 @@
{ lib, ... }:
{
config.lib.stylix = {
mkHexColor = color: "0x${lib.removePrefix "#" color}";
mkOpacityHexColor =
let
opacityHex =
percentage:
lib.throwIfNot (percentage >= 0 && percentage <= 1)
"value must be between 0 and 1 (inclusive): ${toString percentage}"
(lib.toHexString (builtins.floor (percentage * 255 + 0.5)));
in
color: opacity: "0x${opacityHex opacity}${lib.removePrefix "#" color}";
};
}

View file

@ -9,6 +9,7 @@ in
{
imports = [
./palette.nix
../colors.nix
../fonts.nix
../home-manager-integration.nix
../opacity.nix

View file

@ -6,6 +6,7 @@ in
imports = [
./fonts.nix
./palette.nix
../colors.nix
../fonts.nix
../home-manager-integration.nix
../opacity.nix

View file

@ -11,6 +11,7 @@ in
./cursor.nix
./icons.nix
./palette.nix
../colors.nix
../cursor.nix
../fonts.nix
../icons.nix

View file

@ -10,6 +10,7 @@ in
imports = [
./cursor.nix
./palette.nix
../colors.nix
../cursor.nix
../fonts.nix
../home-manager-integration.nix