import QtQuick import QtQuick.Layouts import Quickshell import qs.Components import ZShell.Config import qs.Services GridLayout { id: root property color accentColor: warning ? Colors.palette.m3error : mainColor property real animatedPercentage: 0 readonly property real arcStartAngle: 0.75 * Math.PI readonly property real arcSweep: 1.5 * Math.PI readonly property real dpr: (QsWindow.window as QsWindow)?.devicePixelRatio ?? 1 required property bool horizontal property string icon required property color iconColor required property color mainColor required property double percentage property bool shown: true property color usageColor: warning ? Colors.palette.m3error : mainColor property bool warning: percentage * 100 >= warningThreshold property int warningThreshold: 80 function snap(v) { return Math.round(v * dpr) / dpr; } columnSpacing: Tokens.spacing.medium columns: horizontal ? -1 : 1 percentage: 0 Behavior on animatedPercentage { Anim { } } Component.onCompleted: animatedPercentage = percentage onPercentageChanged: { const next = percentage; if (Math.abs(next - animatedPercentage) >= 0.05) animatedPercentage = next; } MaterialIcon { id: icon Layout.preferredWidth: 16 color: root.iconColor fontStyle: Tokens.font.icon.small text: root.icon } CustomRect { id: track Layout.preferredHeight: root.horizontal ? icon.implicitHeight - Tokens.padding.extraSmall : 4 Layout.preferredWidth: root.horizontal ? 4 : icon.implicitWidth color: Colors.layer(Colors.palette.m3surfaceContainerHigh, 2) radius: Math.min(width, height) / 2 Item { id: clipper anchors.bottom: root.horizontal ? parent.bottom : undefined anchors.horizontalCenter: root.horizontal ? parent.horizontalCenter : undefined anchors.left: root.horizontal ? undefined : parent.left anchors.verticalCenter: root.horizontal ? undefined : parent.verticalCenter clip: true height: root.horizontal ? root.snap(root.percentage * track.height) : track.height * 2 width: root.horizontal ? track.width * 2 : root.snap(root.percentage * track.width) CustomRect { anchors.bottom: root.horizontal ? parent.bottom : undefined anchors.horizontalCenter: root.horizontal ? parent.horizontalCenter : undefined anchors.left: root.horizontal ? undefined : parent.left anchors.verticalCenter: root.horizontal ? undefined : parent.verticalCenter color: root.mainColor height: track.height radius: track.radius width: track.width } } } }