forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdial.slint
More file actions
130 lines (112 loc) · 4.02 KB
/
dial.slint
File metadata and controls
130 lines (112 loc) · 4.02 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT
export global AppState {
out property <int> totalLights: 35;
property <angle> degreesFilledWithLights: 360deg - (startAngle - endAngle);
out property <int> volume: (normalizeAngle(angle - startAngle) / degreesFilledWithLights) * (totalLights + 1);
out property <angle> startAngle: 120deg;
out property <angle> endAngle: 60deg;
out property <angle> angleGap: startAngle - endAngle;
in-out property <angle> angle: startAngle;
out property <length> elementRadius: 185px;
pure public function normalizeAngle(angle: angle) -> angle {
return (angle + 360deg).mod(360deg);
}
}
export component Light {
in property <int> index;
property <angle> gap: (360deg - (AppState.startAngle - AppState.endAngle)) / AppState.totalLights;
property <angle> angle: (index * gap) + AppState.startAngle;
property <bool> lightOn: index <= AppState.volume;
x: AppState.elementRadius * angle.cos();
y: AppState.elementRadius * angle.sin();
width: 0;
height: 0;
states [
lightOn when root.lightOn: {
blueLed.opacity: 0.6;
in {
animate blueLed.opacity {
duration: 100ms;
easing: ease-in-sine;
}
}
out {
animate blueLed.opacity {
duration: 600ms;
easing: ease-out-sine;
}
}
}
]
Image {
source: @image-url("images/light-hole.png");
}
blueLed := Image {
source: @image-url("images/light.png");
opacity: 0;
}
}
export component AppWindow inherits Window {
preferred-width: 500px;
preferred-height: 500px;
background: #1e1d27;
base := Image {
source: @image-url("images/dial-frame.png");
}
ta := TouchArea {
property <length> centerX: self.width / 2;
property <length> centerY: self.height / 2;
property <length> relativeX: ta.mouse-x - centerX;
property <length> relativeY: ta.mouse-y - centerY;
property <angle> lastAngle;
property <bool> hovering: Math.pow(relativeX / 1px, 2) + Math.pow(relativeY / 1px, 2) < metalKnob.width / 2px * metalKnob.height / 2px;
property <bool> touching: false;
width: base.width;
height: base.height;
mouse-cursor: touching ? grabbing : hovering ? grab : default;
pointer-event(event) => {
let newAngle = AppState.normalizeAngle(atan2(relativeY / 1px, relativeX / 1px));
if event.kind == PointerEventKind.down {
if hovering {
touching = true;
lastAngle = newAngle;
}
} else if event.kind == PointerEventKind.up {
touching = false;
} else if event.kind == PointerEventKind.move {
if touching {
let nextAngle = AppState.normalizeAngle(AppState.angle - lastAngle + newAngle);
// Check if the new angle is within the start and end angles
if nextAngle >= AppState.startAngle || nextAngle <= AppState.endAngle {
AppState.angle = nextAngle;
}
lastAngle = newAngle;
}
}
}
}
metalKnob := Image {
source: @image-url("images/metal-dial.png");
transform-rotation: AppState.angle;
}
Image {
source: @image-url("images/metal-lights.png");
}
Image {
source: @image-url("images/dial-trim.png");
}
Rectangle {
x: parent.width / 2;
y: parent.height / 2;
Image {
property <float> r: 0.5;
x: r * root.width / 2 * AppState.angle.cos();
y: r * root.height / 2 * AppState.angle.sin();
source: @image-url("images/indicator.png");
}
for i in AppState.totalLights + 1: Light {
index: i;
}
}
}