| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | component Clip { |
| 5 | // the presence of a Clip element should not impact the rest |
| 6 | } |
| 7 | |
| 8 | MaybeClip := 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 | |
| 24 | component 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 | |
| 37 | TestCase := 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 |
| 68 | auto handle = TestCase::create(); |
| 69 | const TestCase &instance = *handle; |
| 70 | |
| 71 | assert_eq(instance.get_test(), true); |
| 72 | assert_eq(instance.get_el1clip(), false); |
| 73 | |
| 74 | // clip, outside |
| 75 | slint_testing::send_mouse_click(&instance, 37., 27.); |
| 76 | assert_eq(instance.get_touch1(), 0); |
| 77 | assert_eq(instance.get_touch2(), 0); |
| 78 | |
| 79 | // clip, inside |
| 80 | slint_testing::send_mouse_click(&instance, 37., 33.); |
| 81 | assert_eq(instance.get_touch1(), 0); |
| 82 | assert_eq(instance.get_touch2(), 1); |
| 83 | |
| 84 | |
| 85 | // no-clip, outside |
| 86 | slint_testing::send_mouse_click(&instance, 17., 7.); |
| 87 | assert_eq(instance.get_touch1(), 1); |
| 88 | assert_eq(instance.get_touch2(), 1); |
| 89 | |
| 90 | // no-clip, inside |
| 91 | slint_testing::send_mouse_click(&instance, 17., 13.); |
| 92 | assert_eq(instance.get_touch1(), 2); |
| 93 | assert_eq(instance.get_touch2(), 1); |
| 94 | |
| 95 | // now clip also el1 |
| 96 | instance.set_el1clip(true); |
| 97 | slint_testing::send_mouse_click(&instance, 17., 7.); |
| 98 | assert_eq(instance.get_touch1(), 2); |
| 99 | assert_eq(instance.get_touch2(), 1); |
| 100 | |
| 101 | |
| 102 | ``` |
| 103 | |
| 104 | |
| 105 | ```rust |
| 106 | let instance = TestCase::new().unwrap(); |
| 107 | |
| 108 | assert_eq!(instance.get_test(), true); |
| 109 | assert_eq!(instance.get_el1clip(), false); |
| 110 | |
| 111 | // clip, outside |
| 112 | slint_testing::send_mouse_click(&instance, 37., 27.); |
| 113 | assert_eq!(instance.get_touch1(), 0, "a. touch1"); |
| 114 | assert_eq!(instance.get_touch2(), 0, "a. touch2"); |
| 115 | |
| 116 | // clip, inside |
| 117 | slint_testing::send_mouse_click(&instance, 37., 33.); |
| 118 | assert_eq!(instance.get_touch1(), 0, "b. touch1"); |
| 119 | assert_eq!(instance.get_touch2(), 1, "b. touch2"); |
| 120 | |
| 121 | // no-clip, outside |
| 122 | slint_testing::send_mouse_click(&instance, 17., 7.); |
| 123 | assert_eq!(instance.get_touch1(), 1, "c. touch1"); |
| 124 | assert_eq!(instance.get_touch2(), 1, "c. touch2"); |
| 125 | |
| 126 | // no-clip, inside |
| 127 | slint_testing::send_mouse_click(&instance, 17., 13.); |
| 128 | assert_eq!(instance.get_touch1(), 2, "d. touch1"); |
| 129 | assert_eq!(instance.get_touch2(), 1, "d. touch2"); |
| 130 | |
| 131 | // now clip also el1 |
| 132 | instance.set_el1clip(true); |
| 133 | slint_testing::send_mouse_click(&instance, 17., 7.); |
| 134 | assert_eq!(instance.get_touch1(), 2, "e. touch1"); |
| 135 | assert_eq!(instance.get_touch2(), 1, "e. touch2"); |
| 136 | ``` |
| 137 | |
| 138 | */ |
| 139 | |