1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/layout"#]
2// Copyright © SixtyFPS GmbH <info@slint.dev>
3// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
4
5global G {
6 public pure function is-center(pos: length, size: length, parent: length) -> bool {
7 return abs(pos / 1px - (parent - size) / 2px) < 0.001;
8 }
9}
10
11component Foo {
12 r1 := Rectangle { width: 20px; }
13 r2 := Rectangle { height: 20px; y: 20px; }
14 t1 := Text { text: "Foobar"; }
15
16
17 out property <bool> test:
18 G.is-center(r1.x, r1.width, self.width) && r1.y == 0
19 && r2.x == 0 && r2.y == 20px
20 && G.is-center(t1.x, t1.width, self.width) && G.is-center(t1.y, t1.height, self.height);
21}
22
23Old := Rectangle {
24 r1 := Rectangle { width: 20px; }
25 r2 := Rectangle { height: 20px; y: 20px; }
26 t1 := Text { text: "Foobar"; }
27
28 out property <bool> test:
29 r1.x == 0 && r1.y == 0
30 && r2.x == 0 && r2.y == 20px
31 && t1.x == 0 && t1.y == 0;
32}
33
34TestCase := Window {
35 f := Foo {}
36 o := Old {}
37
38 property <bool> test : f.test && o.test;
39}
40
41/*
42```cpp
43auto handle = TestCase::create();
44const TestCase &instance = *handle;
45assert(instance.get_test());
46```
47
48
49```rust
50let instance = TestCase::new().unwrap();
51assert!(instance.get_test());
52```
53
54```js
55var instance = new slint.TestCase({});
56assert(instance.test);
57```
58*/
59}
60
61#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
62 use i_slint_backend_testing as slint_testing;
63 slint_testing::init();
64 let instance = TestCase::new().unwrap();
65 assert!(instance.get_test());
66 Ok(())
67}