calc font fg color using filament color bg
This commit is contained in:
parent
9aa77b0d27
commit
c6355dfa61
1 changed files with 9 additions and 0 deletions
|
|
@ -275,6 +275,7 @@ self.kiri.load(api => {
|
|||
tray_now === tray.id ? `border-color: red` : undefined,
|
||||
tray.tray_color ? undefined : `border-style: dashed`,
|
||||
`background-color:#${tray.tray_color||'000'}`,
|
||||
`color:#${calcFG(tray.tray_color||'000')}`,
|
||||
`min-height:10px`,
|
||||
`aspect-ratio:1`
|
||||
].filter(v => v).join(';')
|
||||
|
|
@ -469,6 +470,14 @@ self.kiri.load(api => {
|
|||
}
|
||||
}
|
||||
|
||||
function calcFG(bg) {
|
||||
let r = parseInt(bg.substring(0, 2), 16);
|
||||
let g = parseInt(bg.substring(2, 4), 16);
|
||||
let b = parseInt(bg.substring(4, 6), 16);
|
||||
let luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
|
||||
return luminance > 0.5 ? "000000" : "FFFFFF";
|
||||
}
|
||||
|
||||
api.event.on("init-done", function() {
|
||||
if (init) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue