slint/tests/cases/layout/horizontal_sizes.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

86 lines
3 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
export component TestCase inherits Rectangle {
width: 300phx;
height: 300phx;
VerticalLayout {
spacing: 0phx;
padding: 0phx;
HorizontalLayout {
spacing: 0phx;
padding: 0phx;
blue-rect := Rectangle {
background: blue;
height: 100phx;
min-width: 100phx;
horizontal-stretch: 0;
}
red-rect := Rectangle {
width: 50px;
background: red;
min-height: 50phx;
}
green-rect := Rectangle {
background: green;
max-width: 20phx;
horizontal-stretch: 2;
}
orange-rect := Rectangle {
background: orange;
width: 10phx;
horizontal-stretch: 8;
}
yellow-rect := Rectangle {
background: yellow;
max-width: 200phx;
horizontal-stretch: 1;
}
pink-rect := Rectangle {
background: pink;
horizontal-stretch: 2;
max-height: 9000phx;
}
}
black-rect := Rectangle {
background: black;
}
}
out property <bool> blue_rect_ok: blue-rect.x == 0phx && blue-rect.y == 0phx && blue-rect.width == 100phx && blue-rect.height == 100phx;
out property <bool> red_rect_ok: red-rect.x == 100phx && red-rect.y == 0phx && red-rect.width == 50phx && red-rect.height == 100phx;
out property <bool> green_rect_ok: green-rect.x == 150phx && green-rect.y == 0phx && green-rect.width == 20phx && green-rect.height == 100phx;
out property <bool> orange_rect_ok: orange-rect.x == 170phx && orange-rect.y == 0phx && orange-rect.width == 10phx && orange-rect.height == 100phx;
out property <bool> yellow_rect_ok: yellow-rect.x == 180phx && yellow-rect.y == 0phx && yellow-rect.width == 120phx/3 && yellow-rect.height == 100phx;
out property <bool> pink_rect_ok: pink-rect.x == 180phx + yellow-rect.width && pink-rect.y == 0phx && pink-rect.width == 120phx*2/3 && pink-rect.height == 100phx;
out property <bool> test: blue_rect_ok && red_rect_ok && green_rect_ok && orange_rect_ok && yellow_rect_ok && pink_rect_ok;
}
/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(instance.get_blue_rect_ok());
assert(instance.get_red_rect_ok());
assert(instance.get_green_rect_ok());
assert(instance.get_orange_rect_ok());
assert(instance.get_yellow_rect_ok());
assert(instance.get_pink_rect_ok());
```
```rust
let instance = TestCase::new().unwrap();
assert!(instance.get_blue_rect_ok());
assert!(instance.get_red_rect_ok());
assert!(instance.get_green_rect_ok());
assert!(instance.get_orange_rect_ok());
assert!(instance.get_yellow_rect_ok());
assert!(instance.get_pink_rect_ok());
```
*/