summaryrefslogtreecommitdiffstats
path: root/inc/render.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2017-05-10 11:03:40 +0200
committerSimon Rettberg2017-05-10 11:03:40 +0200
commite7fb2eafc44d0b5eab79b13432d3e7c4227fd83e (patch)
tree592fe695572d7e7d32b5980d7d5e222bf9989c23 /inc/render.inc.php
parent[statistics] Hide "add beamer" for screens with no EDID (diff)
downloadslx-admin-e7fb2eafc44d0b5eab79b13432d3e7c4227fd83e.tar.gz
slx-admin-e7fb2eafc44d0b5eab79b13432d3e7c4227fd83e.tar.xz
slx-admin-e7fb2eafc44d0b5eab79b13432d3e7c4227fd83e.zip
[weninterface] Improve color list a bit
Diffstat (limited to 'inc/render.inc.php')
-rw-r--r--inc/render.inc.php23
1 files changed, 21 insertions, 2 deletions
diff --git a/inc/render.inc.php b/inc/render.inc.php
index c34c285a..72993ab5 100644
--- a/inc/render.inc.php
+++ b/inc/render.inc.php
@@ -57,10 +57,11 @@ class Render
if (!empty($bgcolor) || !empty($title)) {
self::$header .= '<style type="text/css">' . "\n";
if (!empty($bgcolor)) {
- self::$header .= ".navbar-header { background-color: $bgcolor; }";
+ $fgcolor = self::readableColor($bgcolor);
+ self::$header .= ".navbar-header{background-color:$bgcolor}a.navbar-brand{color:$fgcolor!important}";
}
if (!empty($title)) {
- self::$header .= '#navbar-sub:after { content: "' . self::cssEsc($title) . '";margin:0 }';
+ self::$header .= '#navbar-sub:after{content:"' . self::cssEsc($title) . '";margin:0}';
}
self::$header .= "\n</style>";
}
@@ -302,4 +303,22 @@ class Render
self::$dashboard = $params;
}
+ public static function readableColor($hex) {
+ if (strlen($hex) <= 4) {
+ $cnt = 1;
+ } else {
+ $cnt = 2;
+ }
+ if (preg_match('/^#?([a-f0-9]{'.$cnt.'})([a-f0-9]{'.$cnt.'})([a-f0-9]{'.$cnt.'})$/i', $hex, $out) != 1)
+ return '#000';
+ $chans = array();
+ $f = ($cnt === 1 ? 17 : 1);
+ for ($i = 1; $i <= 3; ++$i) {
+ $out[$i] = (hexdec($out[$i]) * $f);
+ $chans[] = $out[$i] ^ 0x80;
+ }
+ $b = (255 - (0.299 * $out[1] + 0.587 * $out[2] + 0.114 * $out[3])) * 2;
+ return sprintf("#%02x%02x%02x", ($chans[0] + $b) / 3, ($chans[1] + $b) / 3, ($chans[2] + $b) / 3);
+ }
+
}