1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4component Clip {
5 // the presence of a Clip element should not impact the rest
6}
7
8MaybeClip := Rectangle {
9 width: 10phx;
10 height: 10phx;
11 property <int> touch;
12 Rectangle {
13 background: red;
14 x: 5phx;
15 y: -10phx;
16 width: 15phx;
17 height: 15phx;
18 TouchArea {
19 clicked => { touch+=1; }
20 }
21 }
22}
23
24component ClipAlias {
25 in property c <=> r.clip;
26 r := Rectangle {
27 width: 0px;
28 TouchArea {
29 width: root.width;
30 clicked => {
31 debug("Error");
32 }
33 }
34 }
35}
36
37TestCase := Rectangle {
38 height: 100phx;
39 width: 100phx;
40 property <int> touch1 <=> el1.touch;
41 property <int> touch2 <=> el2.touch;
42 property <bool> el1clip;
43
44 el1 := MaybeClip {
45 clip <=> el1clip;
46 x: 10phx;
47 y: 10phx;
48 }
49
50 el2 := MaybeClip {
51 clip: true;
52 x: 30phx;
53 y: 30phx;
54 }
55
56 // MaybeClip must be inlined when "clip" is set, but not when it isn't. Test that we can have
57 // a combination of inlined and non inlined item
58 MaybeClip { x: 5000px; }
59
60 ClipAlias { c: true; width: 100%; height:100%; }
61
62 test_rect := Rectangle { clip: true; }
63 property <bool> test: test_rect.clip;
64}
65
66/*
67```cpp
68auto handle = TestCase::create();
69const TestCase &instance = *handle;
70
71assert_eq(instance.get_test(), true);
72assert_eq(instance.get_el1clip(), false);
73
74// clip, outside
75slint_testing::send_mouse_click(&instance, 37., 27.);
76assert_eq(instance.get_touch1(), 0);
77assert_eq(instance.get_touch2(), 0);
78
79// clip, inside
80slint_testing::send_mouse_click(&instance, 37., 33.);
81assert_eq(instance.get_touch1(), 0);
82assert_eq(instance.get_touch2(), 1);
83
84
85// no-clip, outside
86slint_testing::send_mouse_click(&instance, 17., 7.);
87assert_eq(instance.get_touch1(), 1);
88assert_eq(instance.get_touch2(), 1);
89
90// no-clip, inside
91slint_testing::send_mouse_click(&instance, 17., 13.);
92assert_eq(instance.get_touch1(), 2);
93assert_eq(instance.get_touch2(), 1);
94
95// now clip also el1
96instance.set_el1clip(true);
97slint_testing::send_mouse_click(&instance, 17., 7.);
98assert_eq(instance.get_touch1(), 2);
99assert_eq(instance.get_touch2(), 1);
100
101
102```
103
104
105```rust
106let instance = TestCase::new().unwrap();
107
108assert_eq!(instance.get_test(), true);
109assert_eq!(instance.get_el1clip(), false);
110
111// clip, outside
112slint_testing::send_mouse_click(&instance, 37., 27.);
113assert_eq!(instance.get_touch1(), 0, "a. touch1");
114assert_eq!(instance.get_touch2(), 0, "a. touch2");
115
116// clip, inside
117slint_testing::send_mouse_click(&instance, 37., 33.);
118assert_eq!(instance.get_touch1(), 0, "b. touch1");
119assert_eq!(instance.get_touch2(), 1, "b. touch2");
120
121// no-clip, outside
122slint_testing::send_mouse_click(&instance, 17., 7.);
123assert_eq!(instance.get_touch1(), 1, "c. touch1");
124assert_eq!(instance.get_touch2(), 1, "c. touch2");
125
126// no-clip, inside
127slint_testing::send_mouse_click(&instance, 17., 13.);
128assert_eq!(instance.get_touch1(), 2, "d. touch1");
129assert_eq!(instance.get_touch2(), 1, "d. touch2");
130
131// now clip also el1
132instance.set_el1clip(true);
133slint_testing::send_mouse_click(&instance, 17., 7.);
134assert_eq!(instance.get_touch1(), 2, "e. touch1");
135assert_eq!(instance.get_touch2(), 1, "e. touch2");
136```
137
138*/
139