forked from Shinonome/dots-hyprland
hefty: bar: resources popup: show mem & cpu
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
Control {
|
||||
id: root
|
||||
|
||||
property list<real> valueWeights: [1]
|
||||
property list<real> values: [0.5]
|
||||
property list<color> valueHighlights: ["white"]
|
||||
property list<color> valueTroughs: []
|
||||
|
||||
readonly property list<real> normalizedValueWeights: {
|
||||
const totalWeight = valueWeights.reduce((sum, weight) => sum + weight, 0)
|
||||
return valueWeights.map(weight => weight / totalWeight)
|
||||
}
|
||||
|
||||
readonly property list<real> visualEnds: {
|
||||
let cumsum = 0;
|
||||
let positions = [];
|
||||
for (let i = 0; i < normalizedValueWeights.length; i++) {
|
||||
cumsum += normalizedValueWeights[i];
|
||||
positions.push(cumsum);
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
readonly property list<real> visualPositions: {
|
||||
let positions = [];
|
||||
let lastEnd = 0;
|
||||
for(let i = 0; i < visualEnds.length; i++) {
|
||||
const thisEnd = visualEnds[i];
|
||||
const width = thisEnd - lastEnd;
|
||||
const thisPos = lastEnd + width * values[i];
|
||||
positions.push(thisPos);
|
||||
lastEnd = visualEnds[i];
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
readonly property list<var> visualSegments: {
|
||||
let segs = [];
|
||||
let lastEnd = 0;
|
||||
for(let i = 0; i < visualEnds.length; i++) {
|
||||
const thisEnd = visualEnds[i];
|
||||
const thisPos = visualPositions[i];
|
||||
segs.push([lastEnd, thisPos]);
|
||||
segs.push([thisPos, thisEnd]);
|
||||
lastEnd = visualEnds[i];
|
||||
}
|
||||
return segs;
|
||||
}
|
||||
|
||||
readonly property list<color> segmentColors: {
|
||||
var cols = [];
|
||||
for(let i = 0; i < valueHighlights.length; i++) {
|
||||
cols.push(valueHighlights[i]);
|
||||
cols.push(valueTroughs[i]);
|
||||
}
|
||||
return cols;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import qs.modules.common
|
||||
|
||||
AbstractCombinedProgressBar {
|
||||
id: root
|
||||
|
||||
property real valueBarWidth: 120
|
||||
property real valueBarHeight: 4
|
||||
property real valueBarGap: 4
|
||||
property real valueBarInnerRadius: Appearance.rounding.unsharpen
|
||||
valueHighlights: [Appearance.colors.colPrimary, Appearance.colors.colTertiary]
|
||||
valueTroughs: [Appearance.colors.colSecondaryContainer, Appearance.colors.colTertiaryContainer]
|
||||
|
||||
background: Item {
|
||||
implicitWidth: root.valueBarWidth
|
||||
implicitHeight: root.valueBarHeight
|
||||
}
|
||||
|
||||
// "negligible" = too small that it'd look weird when shown
|
||||
function isNegligibleSegment(seg: var): bool {
|
||||
const wdth = seg[1] - seg[0];
|
||||
const visualWidth = availableWidth * wdth;
|
||||
return (visualWidth <= valueBarGap + valueBarHeight)
|
||||
}
|
||||
|
||||
contentItem: Item {
|
||||
Repeater {
|
||||
model: root.visualSegments
|
||||
|
||||
delegate: Rectangle {
|
||||
required property int index
|
||||
required property var modelData
|
||||
|
||||
visible: !root.isNegligibleSegment(modelData)
|
||||
anchors {
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
}
|
||||
property bool atStart: index == 0
|
||||
property bool atEnd: index == root.visualSegments.length - 1
|
||||
property real displaySegStart: { // swallow previous segments if they're "negligible"
|
||||
var i = index;
|
||||
while ((i > 0 && root.isNegligibleSegment(root.visualSegments[i-1])))
|
||||
i--;
|
||||
return root.visualSegments[i][0]
|
||||
}
|
||||
|
||||
x: {
|
||||
var result = root.availableWidth * displaySegStart;
|
||||
if (!atStart) result += root.valueBarGap / 2;
|
||||
return result;
|
||||
}
|
||||
width: {
|
||||
var result = root.availableWidth * (modelData[1] - displaySegStart)
|
||||
if (atStart || atEnd) result -= root.valueBarGap / 2;
|
||||
else result -= root.valueBarGap;
|
||||
return result;
|
||||
}
|
||||
color: root.segmentColors[index % root.segmentColors.length]
|
||||
|
||||
property real startRadius: atStart ? height / 2 : root.valueBarInnerRadius
|
||||
property real endRadius: atEnd ? height / 2 : root.valueBarInnerRadius
|
||||
|
||||
topLeftRadius: startRadius
|
||||
bottomLeftRadius: startRadius
|
||||
topRightRadius: endRadius
|
||||
bottomRightRadius: endRadius
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user