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

99 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
// Test the propagation of maximum and minimum size through nested grid layouts
export component TestCase inherits Rectangle {
width: 300phx;
height: 300phx;
rect := Rectangle {
layout := HorizontalLayout {
spacing: 0phx;
padding: 0phx;
Rectangle {
background: blue;
max-height: 300phx;
max-width: 300phx;
min-height: 25phx;
}
VerticalLayout {
spacing: 0phx;
padding: 0phx;
Rectangle {
background: red;
min-width: 50phx;
}
Rectangle {
background: green;
}
}
}
}
out property<float> materialized_max_width: layout.max-width / 1phx;
out property<float> materialized_max_height: layout.max-height / 1phx;
out property<float> materialized_min_width: layout.min-width / 1phx;
out property<float> materialized_min_height: layout.min-height / 1phx;
out property<float> materialized_rect_max_width: rect.max-width / 1phx;
out property<float> materialized_rect_max_height: rect.max-height / 1phx;
out property<float> materialized_rect_min_width: rect.min-width / 1phx;
out property<float> materialized_rect_min_height: rect.min-height / 1phx;
out property <bool> test:
materialized_max_height == 300 && materialized_min_width == 50 && materialized_min_height == 25 && materialized_max_width > 100000 &&
materialized_rect_max_height == 300 && materialized_rect_min_width == 50 && materialized_rect_min_height == 25 && materialized_rect_max_width > 100000;
}
/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_materialized_max_height(), 300);
assert_eq(instance.get_materialized_min_width(), 50);
assert_eq(instance.get_materialized_min_height(), 25);
assert_eq(instance.get_materialized_max_width(), std::numeric_limits<float>::max());
assert_eq(instance.get_materialized_rect_max_height(), 300);
assert_eq(instance.get_materialized_rect_min_width(), 50);
assert_eq(instance.get_materialized_rect_min_height(), 25);
assert_eq(instance.get_materialized_rect_max_width(), std::numeric_limits<float>::max());
```
```rust
let instance = TestCase::new().unwrap();
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_materialized_max_height(), 300.);
assert_eq!(instance.get_materialized_min_width(), 50.);
assert_eq!(instance.get_materialized_min_height(), 25.);
assert_eq!(instance.get_materialized_max_width(), f32::MAX);
assert_eq!(instance.get_materialized_rect_max_height(), 300.);
assert_eq!(instance.get_materialized_rect_min_width(), 50.);
assert_eq!(instance.get_materialized_rect_min_height(), 25.);
assert_eq!(instance.get_materialized_rect_max_width(), f32::MAX);
```
```js
const FLT_MAX = 3.4028234663852886e+38;
var instance = new slint.TestCase();
slintlib.private_api.send_mouse_click(instance, 5., 5.);
assert.equal(instance.materialized_max_height, 300);
assert.equal(instance.materialized_min_width, 50);
assert.equal(instance.materialized_min_height, 25);
assert.equal(instance.materialized_max_width, FLT_MAX);
assert.equal(instance.materialized_rect_max_height, 300);
assert.equal(instance.materialized_rect_min_width, 50);
assert.equal(instance.materialized_rect_min_height, 25);
assert.equal(instance.materialized_rect_max_width, FLT_MAX);
```
*/