slint/tests/cases/layout/grid_fixed_size.slint
David Faure 4595f116f4 testing: Modernize layout testcases
I kept seeing distracting warnings when working with these testcases,
and it's better to have good examples when writing new testcases.

I didn't touch the issue_*.slint regression tests, so those will
still be testing the old syntax.
2025-11-12 18:17:24 +01:00

92 lines
2.8 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
SubWithConstraints := Rectangle {
min-height: 20px;
}
export component TestCase inherits Rectangle {
width: 300phx;
height: 300phx;
layout := GridLayout {
spacing: 0phx;
padding: 0phx;
Row {
rect1 := Rectangle {
background: red;
width: 10%;
}
rect2 := Rectangle {
background: blue;
height: 30%;
}
}
Row {
rect3 := SubWithConstraints { // min-height should be ignored because we override
background: green;
height: 20phx;
}
}
Row {
rect4 := Rectangle {
background: cyan;
}
rect5 := Rectangle {
background: yellow;
}
}
}
property <length> expected_y1: 300phx*0.3;
property <length> expected_y2: 300phx*0.3 + 20phx;
property <length> expected_x1: 30phx;
out property <bool> rect1_pos_ok: rect1.x == 0phx && rect1.y == 0phx && rect1.width == expected_x1 && rect1.height == expected_y1;
out property <bool> rect2_pos_ok: rect2.x == expected_x1 && rect2.y == 0phx && rect2.width == 270phx && rect2.height == expected_y1;
out property <bool> rect3_pos_ok: rect3.x == 0phx && rect3.y == expected_y1 && rect3.width == expected_x1 && rect3.height == 20phx;
out property <bool> rect4_pos_ok: rect4.x == 0phx && rect4.y == expected_y2 && rect4.width == expected_x1 && rect4.height == 300phx - expected_y2;
out property <bool> rect5_pos_ok: rect5.x == expected_x1 && rect5.y == expected_y2 && rect5.width == 270phx && rect5.height == 300phx - expected_y2;
out property <bool> test: rect1_pos_ok && rect2_pos_ok && rect3_pos_ok && rect4_pos_ok && rect5_pos_ok;
}
/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
slint_testing::send_mouse_click(&instance, 5., 95.);
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
assert(instance.get_rect3_pos_ok());
assert(instance.get_rect4_pos_ok());
assert(instance.get_rect5_pos_ok());
```
```rust
let instance = TestCase::new().unwrap();
slint_testing::send_mouse_click(&instance, 5., 95.);
assert!(instance.get_rect1_pos_ok());
assert!(instance.get_rect2_pos_ok());
assert!(instance.get_rect3_pos_ok());
assert!(instance.get_rect4_pos_ok());
assert!(instance.get_rect5_pos_ok());
```
```js
var instance = new slint.TestCase();
slintlib.private_api.send_mouse_click(instance, 5., 5.);
assert(instance.rect1_pos_ok);
assert(instance.rect2_pos_ok);
assert(instance.rect3_pos_ok);
assert(instance.rect4_pos_ok);
assert(instance.rect5_pos_ok);
```
*/