-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Adjust theming color calculations using sRGB luma #7705
Conversation
Yes - this is awesome. I also noticed that one and nice that it is finally fixed. |
apps/theming/lib/Util.php
Outdated
@@ -90,19 +90,44 @@ public function elementColor($color) { | |||
* @return float | |||
*/ | |||
public function calculateLuminance($color) { | |||
$rgb = $this->hexToRGB($color); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easier approach to write this code:
list($red, $green, $blue) = $this->hexToRGB($color);
See https://secure.php.net/manual/en/function.list.php#refsect1-function.list-examples
based on https://robots.thoughtbot.com/closer-look-color-lightness Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
698632a
to
9b668d0
Compare
Codecov Report
@@ Coverage Diff @@
## master #7705 +/- ##
============================================
+ Coverage 51.18% 51.18% +<.01%
- Complexity 24948 24950 +2
============================================
Files 1605 1605
Lines 94923 94927 +4
Branches 1376 1376
============================================
+ Hits 48584 48589 +5
+ Misses 46339 46338 -1
|
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Please review @nextcloud/theming |
This will invalidate the android app's code again? |
As I understand it is only a refined calculation. |
Yes, if clients use the text-color entry in the capabilities, there will be no other change required. I guess it's fine for android then. What about @nextcloud/ios ? Do you the servers text color value or do you do your own calculations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me :D
I don't know if it should be better open a new issue/pull but, dealing with this topic, this is my view on choosing the right color for icons and text. Any algorithm would not fit the best choice for every colorscheme and tastes, so I think a new custom parameter should be added in the theming app, as "Inverted" (or "Invert color" or other). This way an user could manually choose the right foreground color, expecially when the main color is a borderline one (i.e. when a single step value changes the foreground color). The new option would directly force the "inverted" variable value, by inverting the calculated one and definitely solve the issue forever. If you like the idea I could open a new issue/pull, or the solution could be integrated in this pull. |
The theming color calculation is currently using the lightness of a color to decide if icons should be inverted in the app menu or not. However sRGB Luma provides a way better algorithm for deciding if black or white icons should be used on a colored background. (See https://robots.thoughtbot.com/closer-look-color-lightness for reference)
The following example shows the icon inverting the old way (on the left) and the new way (on the right): Color invert comparison old vs. new
Especially for intense color values like #FFFF00 this will provide far better results.
Fixes #7401