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

81 lines
2.4 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
//include_path: ../../../demos/printerdemo/ui/images/
export component TestCase inherits Rectangle {
width: 500phx;
height: 2000phx;
VerticalLayout {
padding: 0px;
spacing: 0px;
top_image := Image {
source: @image-url("cat.jpg");
}
HorizontalLayout {
padding: 0px;
spacing: 0px;
Rectangle {
background: yellow;
width: 300phx;
}
second_image := Image {
source: @image-url("cat.jpg");
}
}
Rectangle {
background: pink;
GridLayout {
spacing: 0;
padding: 0;
Row {
Rectangle { }
}
Row {
hfw_rect := Rectangle {
background: orange;
height: self.width / 2;
}
Rectangle { }
}
}
}
Image { }
}
out property <length> top_image_height: top_image.height;
out property <length> second_image_height: second_image.height;
out property <length> second_image_width: second_image.width;
out property <bool> hfw_rect_ok: hfw_rect.width == 250phx && hfw_rect.height == 125phx;
out property <bool> test: top_image_height == 750phx && second_image_width == 200phx && second_image_height == 300phx && hfw_rect_ok;
}
/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert_eq(instance.get_top_image_height(), 750.);
assert_eq(instance.get_second_image_width(), 200.);
assert_eq(instance.get_second_image_height(), 300.);
assert(instance.get_hfw_rect_ok());
```
```rust
let instance = TestCase::new().unwrap();
assert_eq!(instance.get_top_image_height(), 750.);
assert_eq!(instance.get_second_image_width(), 200.);
assert_eq!(instance.get_second_image_height(), 300.);
assert!(instance.get_hfw_rect_ok());
```
```js
var instance = new slint.TestCase();
assert.equal(instance.top_image_height, 750.);
assert.equal(instance.second_image_width, 200.);
assert.equal(instance.second_image_height, 300.);
assert(instance.hfw_rect_ok);
```
*/