Skip to content

Commit

Permalink
try to fix too dark or bright themed icons
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen committed May 9, 2023
1 parent fc07627 commit 9eccd3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion apps/theming/lib/IconBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ public function colorSvg($app, $image) {
}
$svg = file_get_contents($imageFile);
if ($svg !== false && $svg !== "") {
$color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
$primaryColor = $this->themingDefaults->getColorPrimary();
$luminance = $this->util->calculateLuminance($primaryColor);
$isBrightColor = false;
if ($luminance > 0.8) {
$isBrightColor = true;
}
$color = $this->util->elementColor($primaryColor, $isBrightColor);
$svg = $this->util->colorizeSvg($svg, $color);
return $svg;
} else {
Expand Down
4 changes: 2 additions & 2 deletions apps/theming/lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public function elementColor($color, bool $brightBackground = true) {

if ($brightBackground && $luminance > 0.8) {
// If the color is too bright in bright mode, we fall back to a darker gray
return '#aaaaaa';
return $this->darken($color, 20);
}

if (!$brightBackground && $luminance < 0.2) {
// If the color is too dark in dark mode, we fall back to a brighter gray
return '#8c8c8c';
return $this->lighten($color, 20);
}

return $color;
Expand Down

0 comments on commit 9eccd3a

Please sign in to comment.