| 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 Item { |
| 5 | callback pointer-event <=> touch.pointer-event; |
| 6 | touch := TouchArea {} |
| 7 | } |
| 8 | |
| 9 | component Issue3148 { |
| 10 | out property <length> result; |
| 11 | Item { |
| 12 | x: 42px; |
| 13 | pointer-event => { |
| 14 | debug(self.absolute-position.x - root.absolute-position.x); |
| 15 | } |
| 16 | init => { |
| 17 | result = self.absolute-position.x - root.absolute-position.x |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | export component TestCase { |
| 23 | width: 500phx; |
| 24 | height: 500phx; |
| 25 | |
| 26 | property <bool> simple-inner-ok: simple-inner.absolute-position.x == 40phx && simple-inner.absolute-position.y == 60phx; |
| 27 | |
| 28 | out property <string> inner-popup; |
| 29 | // The absolute-position is only absolute within the popup. |
| 30 | // If we changed the behavior to be relative within the window, then we'd need to uncomment the commented numbers |
| 31 | out property <string> inner-popup-expected: "x=" + (/*10+100+0+8*/-5+200) + " y=" + (/*20+0+50+7*/-5-200); |
| 32 | |
| 33 | Rectangle { |
| 34 | x: 10phx; |
| 35 | y: 20phx; |
| 36 | |
| 37 | simple-inner := Rectangle { |
| 38 | x: 30phx; |
| 39 | y: 40phx; |
| 40 | } |
| 41 | |
| 42 | init => {debug(hl.preferred-height) } |
| 43 | |
| 44 | hl := HorizontalLayout { |
| 45 | if true:Rectangle { |
| 46 | preferred-height: 200phx; |
| 47 | Rectangle { |
| 48 | x: 100phx; |
| 49 | init => { |
| 50 | popup.show(); |
| 51 | } |
| 52 | Rectangle { |
| 53 | y: 50phx; |
| 54 | popup := PopupWindow { |
| 55 | x: 8phx; |
| 56 | y: 7phx; |
| 57 | Rectangle { |
| 58 | x: -5phx; |
| 59 | y: -5phx; |
| 60 | init => { debug(vl.preferred-height) } |
| 61 | vl:=VerticalLayout { |
| 62 | if true: Rectangle { |
| 63 | Rectangle { |
| 64 | x: 200phx; |
| 65 | y: -200phx; |
| 66 | Rectangle { |
| 67 | init => { |
| 68 | inner-popup = "x=" + (self.absolute-position.x/1px) + " y=" + (self.absolute-position.y/1px); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | empty1 := Rectangle { |
| 82 | Rectangle { |
| 83 | empty2 := Rectangle { |
| 84 | |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | xxx := Issue3148 { width: 50%; } |
| 89 | out property <bool> test: simple-inner-ok && xxx.result == 42px && empty1.absolute-position == empty2.absolute-position |
| 90 | && inner-popup == inner-popup-expected; |
| 91 | out property <Point> coords <=> simple-inner.absolute-position; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | ```rust |
| 96 | let instance = TestCase::new().unwrap(); |
| 97 | assert!(instance.get_test()); |
| 98 | let pos: slint::LogicalPosition = instance.get_coords(); |
| 99 | assert_eq!(pos.x, 40.); |
| 100 | assert_eq!(pos.y, 60.); |
| 101 | ``` |
| 102 | |
| 103 | ```cpp |
| 104 | auto handle = TestCase::create(); |
| 105 | const TestCase &instance = *handle; |
| 106 | assert(instance.get_test()); |
| 107 | slint::LogicalPosition pos = instance.get_coords(); |
| 108 | assert_eq(pos.x, 40); |
| 109 | assert_eq(pos.y, 60); |
| 110 | ``` |
| 111 | |
| 112 | ```js |
| 113 | let instance = new slint.TestCase({}); |
| 114 | assert(instance.test, 1); |
| 115 | assert.deepEqual(instance.coords, { x: 40, y: 60}); |
| 116 | ``` |
| 117 | |
| 118 | */ |
| 119 | |