This commit is contained in:
Flummi 2024-01-20 16:20:14 +01:00
parent 65959a5c4b
commit 04ad311289
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817
3 changed files with 24 additions and 36 deletions

View File

@ -119,43 +119,43 @@ QQC2.Pane {
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.1, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.1, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.2, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.2, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.3, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.3, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.4, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.4, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.5, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.5, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.6, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.6, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.7, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.7, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.8, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.8, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor(.9, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor(.9, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
Text { Text {
text: "█" text: "█"
color: Helper.interpolateColor( 1, cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString()) color: Helper.interpolateColor( 1, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
} }
} }
} }

View File

@ -8,34 +8,22 @@ const batteryIcon = batteryPercent => ({
"-1": "battery-ac-adapter" "-1": "battery-ac-adapter"
})[batteryPercent] ?? "audio-headphones-symbolic"; })[batteryPercent] ?? "audio-headphones-symbolic";
const hex2rgb = hex => ({ const hex2rgb = (hex, h = hex.replace('#', '0x')) => ({ r: h >> 16 & 255, g: h >> 8 & 255, b: h & 255 });
r: parseInt(hex.slice(1, 3), 16), const rgb2Hex = rgb => "#" + ((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).toString(16).slice(1);
g: parseInt(hex.slice(3, 5), 16),
b: parseInt(hex.slice(5, 7), 16)
});
const rgb2Hex = rgb => `#${((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).toString(16).slice(1)}`;
const interpolateColor = (f, c0, c1, c3) => { const interpolateColor = (ff, c) => {
if(isNaN(f)) return "transparent"; if(!ff) return "transparent";
c0 = hex2rgb(c0); if(ff >= 1) return c.pop();
c1 = hex2rgb(c1); if(ff <= 0) return c[0];
c3 = hex2rgb(c3);
let color1 = c0;
let color2 = c1;
let fade = f;
if(c3) { let f = ff * (c.length - 1);
fade *= 2; const i = ~~f;
if(fade >= 1) { f -= i;
fade--; const [ c1, c2 ] = [ hex2rgb(c[i]), hex2rgb(c[i + 1]) ];
color1 = c1;
color2 = c3;
}
}
return rgb2Hex({ return rgb2Hex({
r: parseInt(~~(color1.r + ((color2.r - color1.r) * fade)), 10), r: parseInt(~~(c1.r + ((c2.r - c1.r) * f)), 10),
g: parseInt(~~(color1.g + ((color2.g - color1.g) * fade)), 10), g: parseInt(~~(c1.g + ((c2.g - c1.g) * f)), 10),
b: parseInt(~~(color1.b + ((color2.b - color1.b) * fade)), 10), b: parseInt(~~(c1.b + ((c2.b - c1.b) * f)), 10)
}); });
}; };

View File

@ -53,7 +53,7 @@ Item {
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
color: Helper.interpolateColor(parseFloat("." + batteryPercent), colorEmpty, colorHalf, colorFull) color: Helper.interpolateColor(parseFloat("." + batteryPercent), [ colorEmpty, colorHalf, colorFull ])
width: parent.width * Math.max(0, Math.min(batteryPercent, 100)) / 100 width: parent.width * Math.max(0, Math.min(batteryPercent, 100)) / 100
} }
Kirigami.Icon { // headphones icon Kirigami.Icon { // headphones icon