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

fix(config): select fg by maximizing contrast rather than check if a color is dark #316

Merged
merged 3 commits into from
Sep 16, 2024

Conversation

mehalter
Copy link
Contributor

@mehalter mehalter commented Sep 15, 2024

Description

This PR changes a bit of of the internal logic used for calculating the foreground for a given background color. Currently it uses an algorithm to guess if the dark or light color is better. This rather uses the contrast ratio metric as described by the WCAG to maximize visual difference between the foreground and background.

Let me know what you think of this solution! Thanks so much for a great plugin!

EDIT: moved from Euclidian distance in the RGB space to the official contrast definition by the WCAG for identifying the contrast between foreground and background colors which accounts for difference in color perception to the human eye. (https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html)

Related Issue(s)

Fixes #315

Screenshots

Here is a color that resolves incorrectly without this PR:

image

Here is the same color with this PR:

image

@mehalter mehalter changed the title fix: select fg by maximizing contrast rather than check if a color is dark fix(config): select fg by maximizing contrast rather than check if a color is dark Sep 15, 2024
@mehalter mehalter force-pushed the fg_fix branch 2 times, most recently from e217aa3 to 85a751c Compare September 16, 2024 00:45
@folke folke merged commit 76990a9 into folke:main Sep 16, 2024
11 checks passed
@folke
Copy link
Owner

folke commented Sep 16, 2024

Awesome, ty!

@mehalter mehalter deleted the fg_fix branch September 16, 2024 09:47
folke pushed a commit that referenced this pull request Sep 16, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.4.0](v1.3.0...v1.4.0)
(2024-09-16)


### Features

* **fzf:** add fzf-lua support in Readme & add TodoFzfLua command
([#312](#312))
([6d6cf47](6d6cf47))


### Bug Fixes

* **config:** select `fg` by maximizing contrast rather than check if a
color is dark
([#316](#316))
([76990a9](76990a9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

bug: Util.is_dark resolves incorrectly.
2 participants