forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotter.slint
55 lines (50 loc) · 1.96 KB
/
plotter.slint
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
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
import { Slider, GroupBox, HorizontalBox, VerticalBox } from "std-widgets.slint";
export component MainWindow inherits Window {
title: "Slint Plotter Integration Example";
preferred-width: 800px;
preferred-height: 600px;
pure callback render_plot(float /* pitch */, float /* yaw */, float /* amplitude */) -> image;
in-out property <float> pitch: 0.15;
in-out property <float> yaw: 0.5;
VerticalBox {
Text {
font-size: 20px;
text: "2D Gaussian PDF";
horizontal-alignment: center;
}
Image {
source: root.render_plot(root.pitch, root.yaw, amplitude-slider.value / 10);
touch := TouchArea {
property <float> pressed-pitch;
property <float> pressed-yaw;
pointer-event(event) => {
if (event.button == PointerEventButton.left && event.kind == PointerEventKind.down) {
self.pressed-pitch = root.pitch;
self.pressed-yaw = root.yaw;
}
}
moved => {
if (self.enabled && self.pressed) {
root.pitch = self.pressed-pitch + (touch.mouse-y - touch.pressed-y) / self.height * 3.14;
root.yaw = self.pressed-yaw - (touch.mouse-x - touch.pressed-x) / self.width * 3.14;
}
}
mouse-cursor: self.pressed ? MouseCursor.grabbing : MouseCursor.grab;
}
}
HorizontalBox {
Text {
text: "Amplitude:";
font-weight: 600;
vertical-alignment: center;
}
amplitude-slider := Slider {
minimum: 0;
maximum: 100;
value: 50;
}
}
}
}