summaryrefslogtreecommitdiff
path: root/components/SimpleResource.qml
blob: 077506986e2a220076358225fb091e760bcf76c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import QtQuick
import Quickshell
import QtQuick.Layouts
import qs.config
import qs.components

Item {
    id: root

    required property real value
    required property string suffix // unit
    required property string icon
    property string text: Math.round(root.value * 100) + root.suffix
    property real thresholdL1: 40 / 100
    property real thresholdL2: thresholdL1 * 1.5
    property real thresholdL3: thresholdL2 * 1.5
    property color thresholdColorL1: Colors.cyan
    property color thresholdColorL2: Colors.yellow
    property color thresholdColorL3: Colors.red

    implicitWidth: layout.implicitWidth
    implicitHeight: layout.implicitHeight

    RowLayout {
        id: layout

        spacing: Bar.resourceIconTextSpacing

        Item {
            Layout.fillWidth: true
        }

        Icon {
            text: root.icon
            color: root.value < root.thresholdL1 ? WallustColors.foreground : root.value >= root.thresholdL3 ? root.thresholdColorL3 : root.value >= root.thresholdL2 ? root.thresholdColorL2 : root.thresholdColorL1
        }
        IText {
            animate: true
            text: root.text
            color: root.value < root.thresholdL1 ? WallustColors.foreground : root.value >= root.thresholdL3 ? root.thresholdColorL3 : root.value >= root.thresholdL2 ? root.thresholdColorL2 : root.thresholdColorL1
        }

        Item {
            Layout.fillWidth: true
        }
    }
}