forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcircledraw.slint
114 lines (94 loc) · 3.08 KB
/
circledraw.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
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
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: MIT
import { LineEdit, Button, Slider, StandardListView, VerticalBox } from "std-widgets.slint";
struct Circle { x: length, y: length, d: length }
export component MainWindow inherits Window {
in property <[Circle]> model;
in property <bool> undoable: false;
in property <bool> redoable: false;
callback undo_clicked();
callback redo_clicked();
callback background_clicked(length,length);
callback circle_resized(int, length);
private property <int> clicked-idx: -1;
private property <Circle> selected-circle;
preferred-width: 500px;
preferred-height: 400px;
VerticalBox {
HorizontalLayout {
alignment: center;
spacing: 12px;
Button {
text: "Undo";
enabled <=> root.undoable;
clicked => { root.undo-clicked() }
}
Button {
text: "Redo";
enabled <=> root.redoable;
clicked => { root.redo-clicked() }
}
}
Rectangle {
background: white;
border-color: black;
border-width: 2px;
clip: true;
TouchArea {
clicked => {
root.background_clicked(self.pressed_x, self.pressed_y);
}
width: 100%;
height: 100%;
}
for circle[idx] in root.model : Rectangle {
background: root.clicked-idx == idx ? gray : white;
border-color: black;
border-width: 2px;
border-radius: self.width / 2;
height: self.width;
width: circle.d;
x: circle.x - self.width/2;
y: circle.y - self.height/2;
TouchArea {
clicked => {
root.selected-circle = circle;
root.clicked-idx = idx;
}
height: 100%;
width: 100%;
}
}
}
}
if (root.clicked-idx != -1) : TouchArea {
clicked => { root.clicked-idx = -1; }
height: 100%;
width: 100%;
}
if (root.clicked-idx != -1) : Rectangle {
background: lightgray;
height: 30%;
width: 70%;
x: (parent.width - self.width) / 2;
y: parent.height - self.height - parent.height * 5%;
TouchArea {
height: 100%;
width: 100%;
}
VerticalBox {
Text {
text: "Adjust diameter of circle at (" + root.selected-circle.x / 1px + ", " + root.selected-circle.y / 1px + ").";
wrap: word-wrap;
}
Slider {
changed(diameter) => {
root.circle_resized(root.clicked-idx, diameter *1px);
}
minimum: 4;
maximum: 100;
value: root.selected-circle.d / 1px;
}
}
}
}