Skip to content

feat: Add with_opacity() helper for color opacity#49

Open
sojotype wants to merge 4 commits intolukeyou05:mainfrom
sojotype:feat-hexa
Open

feat: Add with_opacity() helper for color opacity#49
sojotype wants to merge 4 commits intolukeyou05:mainfrom
sojotype:feat-hexa

Conversation

@sojotype
Copy link

Summary

This PR adds support for a new hexa() color format that allows specifying colors with alpha transparency using a more readable percentage-based syntax.

Changes

  • New feature: hexa(color,X%) format support
    • color can be accent (Windows accent color) or hex code
    • X% specifies opacity percentage (0-100%)
  • Implementation: Added parse_hexa() function in src/colors.rs
  • Documentation: Updated README.md and config.yaml with examples
  • Tests: Added comprehensive test coverage for all hexa format variations

Examples

active_color: "hexa(accent,40%)"    # Windows accent with 40% opacity
active_color: "hexa(#ff0000,60%)"   # Red with 60% opacity
active_color: "hexa(00ff00,50%)"    # Green with 50% opacity (# optional)

Benefits

  • More intuitive than hex alpha values (e.g., hexa(#ff0000,60%) vs #ff000099)
  • Supports both accent colors and custom hex codes
  • Alpha override functionality for existing hex codes with alpha

sojotype and others added 2 commits August 28, 2025 03:15
…rt for hexa(color,X%) format where:\n - color can be 'accent' for Windows accent color or hex code\n - X% specifies opacity percentage\n- Implements parse_hexa() function to handle new format\n- Updates get_color_from_hex() to detect and parse hexa format\n- Adds comprehensive tests for all hexa format variations\n- Supports hex codes with and without # prefix\n- Alpha value overrides any existing alpha in hex codes\n- Updates documentation in README.md and config.yaml with examples\n- Provides clear examples of hexa() usage in config files
@lukeyou05
Copy link
Owner

Since hexa() can also be used for non-hex values (i.e. accent), and since percentages are more commonly seen when working with opacity rather than alpha, I wonder if it would be better to name it something like with_opacity(). Thoughts?

@sojotype
Copy link
Author

sojotype commented Sep 7, 2025

Since hexa() can also be used for non-hex values (i.e. accent), and since percentages are more commonly seen when working with opacity rather than alpha, I wonder if it would be better to name it something like with_opacity(). Thoughts?

That makes sense) Thanks for the idea)

@sojotype sojotype changed the title feat: Add hexa() color format with alpha transparency feat: Add with_opacity() helper for color opacity Sep 7, 2025
}

fn get_color_from_hex(hex: &str) -> D2D1_COLOR_F {
// Check if the string is in with_opacity(color,X%) format
Copy link
Owner

Choose a reason for hiding this comment

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

We should probably move the parse_with_opacity() call outside get_color_from_hex() since the names are different now. I think the best way to do that would be to break out lines 426 - 432 into a separate function called something like get_color_with_opacity(), and then use that function in lines 85 and 108 (right next to the other get_accent_color() and get_color_from_hex() calls). That does lead to more repeated code but I could refactor that out in the future.

Copy link
Owner

@lukeyou05 lukeyou05 Sep 11, 2025

Choose a reason for hiding this comment

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

The config section in the README is meant to track whatever is in the latest release, so we should revert everything here since it won't be released until later.

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.

2 participants