summaryrefslogtreecommitdiffstats
path: root/src/graphs3d/qml/resources/AxisLabel.qml
blob: 3af14ad4560faef15ccc945bccdf23a5c3d0ff43 (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
48
49
50
51
52
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick3D

Model {
    id: root
    source: "#Rectangle"
    pickable: true
    castsShadows: false

    property string labelText: ""
    property color backgroundColor: "gray"
    property bool backgroundVisible: false
    property color labelTextColor: "transparent"
    property bool borderVisible: false
    property font labelFont
    property real labelWidth: -1
    property real labelHeight: -1

    materials: PrincipledMaterial {
        lighting: PrincipledMaterial.NoLighting
        alphaMode: PrincipledMaterial.Blend
        baseColorMap: Texture {
            sourceItem: Item {
                id: labelItem
                width: root.labelWidth
                height: root.labelHeight

                Rectangle {
                    id: labelBackground
                    anchors.fill: parent
                    color: root.backgroundColor
                    visible: root.backgroundVisible
                    border.color: root.labelTextColor
                    border.width: root.borderVisible
                                  ? Math.max(0.5, (text0.font.pointSize / 16)) : 0
                    radius: 4
                }

                Text {
                    id: text0
                    anchors.centerIn: parent
                    color: root.labelTextColor
                    text: root.labelText
                    font: root.labelFont
                }
            }
        }
    }
}