slint/tests/cases/absolute_coords.slint
Olivier Goffart 34152611b3 PopupWindow: fix absolute-position property within a PopupWindow
We were actually skipping two element (the popup and the popup parent)
Also this broke the positioning of sub-popup.

The "fix" is to not get a parent for popup window.
This will also have the side effect of fixing the focus issue
2024-12-09 15:58:16 +01:00

118 lines
3.6 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
component Item {
callback pointer-event <=> touch.pointer-event;
touch := TouchArea {}
}
component Issue3148 {
out property <length> result;
Item {
x: 42px;
pointer-event => {
debug(self.absolute-position.x - root.absolute-position.x);
}
init => {
result = self.absolute-position.x - root.absolute-position.x
}
}
}
export component TestCase {
width: 500phx;
height: 500phx;
property <bool> simple-inner-ok: simple-inner.absolute-position.x == 40phx && simple-inner.absolute-position.y == 60phx;
out property <string> inner-popup;
// The absolute-position is only absolute within the popup.
// If we changed the behavior to be relative within the window, then we'd need to uncomment the commented numbers
out property <string> inner-popup-expected: "x=" + (/*10+100+0+8*/-5+200) + " y=" + (/*20+0+50+7*/-5-200);
Rectangle {
x: 10phx;
y: 20phx;
simple-inner := Rectangle {
x: 30phx;
y: 40phx;
}
init => {debug(hl.preferred-height) }
hl := HorizontalLayout {
if true:Rectangle {
preferred-height: 200phx;
Rectangle {
x: 100phx;
init => {
popup.show();
}
Rectangle {
y: 50phx;
popup := PopupWindow {
x: 8phx;
y: 7phx;
Rectangle {
x: -5phx;
y: -5phx;
init => { debug(vl.preferred-height) }
vl:=VerticalLayout {
if true: Rectangle {
Rectangle {
x: 200phx;
y: -200phx;
Rectangle {
init => {
inner-popup = "x=" + (self.absolute-position.x/1px) + " y=" + (self.absolute-position.y/1px);
}
}
}
}
}
}
}
}
}
}
}
}
empty1 := Rectangle {
Rectangle {
empty2 := Rectangle {
}
}
}
xxx := Issue3148 { width: 50%; }
out property <bool> test: simple-inner-ok && xxx.result == 42px && empty1.absolute-position == empty2.absolute-position
&& inner-popup == inner-popup-expected;
out property <Point> coords <=> simple-inner.absolute-position;
}
/*
```rust
let instance = TestCase::new().unwrap();
assert!(instance.get_test());
let pos: slint::LogicalPosition = instance.get_coords();
assert_eq!(pos.x, 40.);
assert_eq!(pos.y, 60.);
```
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(instance.get_test());
slint::LogicalPosition pos = instance.get_coords();
assert_eq(pos.x, 40);
assert_eq(pos.y, 60);
```
```js
let instance = new slint.TestCase({});
assert(instance.test, 1);
assert.deepEqual(instance.coords, { x: 40, y: 60});
```
*/