1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: MIT |
3 | |
4 | import { Slider, GroupBox, HorizontalBox, VerticalBox } from "std-widgets.slint" ; |
5 | |
6 | export component MainWindow inherits Window { |
7 | in-out property <float> pitch: 0.15; |
8 | in-out property <float> yaw: 0.5; |
9 | |
10 | pure callback render_plot(/* pitch */ float, /* yaw */ float, /* amplitude */ float) -> image; |
11 | |
12 | title: "Slint Plotter Integration Example" ; |
13 | preferred-width: 800px; |
14 | preferred-height: 600px; |
15 | |
16 | VerticalBox { |
17 | Text { |
18 | font-size: 20px; |
19 | text: "2D Gaussian PDF" ; |
20 | horizontal-alignment: center; |
21 | } |
22 | |
23 | Image { |
24 | source: root.render_plot(root.pitch, root.yaw, amplitude-slider.value / 10); |
25 | touch := TouchArea { |
26 | property <float> pressed-pitch; |
27 | property <float> pressed-yaw; |
28 | |
29 | pointer-event(event) => { |
30 | if (event.button == PointerEventButton.left && event.kind == PointerEventKind.down) { |
31 | self.pressed-pitch = root.pitch; |
32 | self.pressed-yaw = root.yaw; |
33 | } |
34 | } |
35 | moved => { |
36 | if (self.enabled && self.pressed) { |
37 | root.pitch = self.pressed-pitch + (touch.mouse-y - touch.pressed-y) / self.height * 3.14; |
38 | root.yaw = self.pressed-yaw - (touch.mouse-x - touch.pressed-x) / self.width * 3.14; |
39 | } |
40 | } |
41 | mouse-cursor: self.pressed ? MouseCursor.grabbing : MouseCursor.grab; |
42 | } |
43 | } |
44 | |
45 | HorizontalBox { |
46 | Text { |
47 | text: "Amplitude:" ; |
48 | font-weight: 600; |
49 | vertical-alignment: center; |
50 | } |
51 | |
52 | amplitude-slider := Slider { |
53 | minimum: 0; |
54 | maximum: 100; |
55 | value: 50; |
56 | } |
57 | } |
58 | } |
59 | } |
60 | |