extract loadColor gradient function into Theme service
This commit is contained in:
parent
1db16b435c
commit
7d9800374f
5 changed files with 16 additions and 39 deletions
|
|
@ -8,14 +8,6 @@ Column {
|
|||
|
||||
property bool active: true
|
||||
|
||||
function _loadColor(pct) {
|
||||
const t = Math.max(0, Math.min(100, pct)) / 100;
|
||||
const a = t < 0.5 ? S.Theme.base0B : S.Theme.base0A;
|
||||
const b = t < 0.5 ? S.Theme.base0A : S.Theme.base08;
|
||||
const u = t < 0.5 ? t * 2 : (t - 0.5) * 2;
|
||||
return Qt.rgba(a.r + (b.r - a.r) * u, a.g + (b.g - a.g) * u, a.b + (b.b - a.b) * u, 1);
|
||||
}
|
||||
|
||||
function _fmt(gb) {
|
||||
return gb >= 10 ? gb.toFixed(1) + "G" : gb.toFixed(2) + "G";
|
||||
}
|
||||
|
|
@ -41,7 +33,7 @@ Column {
|
|||
anchors.rightMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: S.SystemStats.gpuUsage + "%"
|
||||
color: root._loadColor(S.SystemStats.gpuUsage)
|
||||
color: S.Theme.loadColor(S.SystemStats.gpuUsage)
|
||||
font.pixelSize: S.Theme.fontSize
|
||||
font.family: S.Theme.fontFamily
|
||||
font.bold: true
|
||||
|
|
@ -70,7 +62,7 @@ Column {
|
|||
Rectangle {
|
||||
width: parent.width * Math.min(1, S.SystemStats.gpuUsage / 100)
|
||||
height: parent.height
|
||||
color: root._loadColor(S.SystemStats.gpuUsage)
|
||||
color: S.Theme.loadColor(S.SystemStats.gpuUsage)
|
||||
radius: 3
|
||||
Behavior on width {
|
||||
enabled: root.active
|
||||
|
|
@ -113,7 +105,7 @@ Column {
|
|||
const offset = maxSamples - d.length;
|
||||
for (let i = 0; i < d.length; i++) {
|
||||
const barH = Math.max(1, height * d[i] / 100);
|
||||
const col = root._loadColor(d[i]);
|
||||
const col = S.Theme.loadColor(d[i]);
|
||||
ctx.fillStyle = col.toString();
|
||||
ctx.fillRect((offset + i) * bw, height - barH, Math.max(1, bw - 0.5), barH);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue