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 | |
5 | // Test the propagation of maximum and minimum size through nested grid layouts |
6 | |
7 | TestCase := Rectangle { |
8 | width: 300phx; |
9 | height: 300phx; |
10 | |
11 | rect := Rectangle { |
12 | |
13 | layout := HorizontalLayout { |
14 | spacing: 0phx; |
15 | padding: 0phx; |
16 | Rectangle { |
17 | background: blue; |
18 | max-height: 300phx; |
19 | max-width: 300phx; |
20 | min-height: 25phx; |
21 | } |
22 | VerticalLayout { |
23 | spacing: 0phx; |
24 | padding: 0phx; |
25 | Rectangle { |
26 | background: red; |
27 | min-width: 50phx; |
28 | } |
29 | Rectangle { |
30 | background: green; |
31 | } |
32 | } |
33 | } |
34 | } |
35 | |
36 | property<int> materialized_max_width: layout.max-width / 1phx; |
37 | property<int> materialized_max_height: layout.max-height / 1phx; |
38 | property<int> materialized_min_width: layout.min-width / 1phx; |
39 | property<int> materialized_min_height: layout.min-height / 1phx; |
40 | |
41 | property<int> materialized_rect_max_width: rect.max-width / 1phx; |
42 | property<int> materialized_rect_max_height: rect.max-height / 1phx; |
43 | property<int> materialized_rect_min_width: rect.min-width / 1phx; |
44 | property<int> materialized_rect_min_height: rect.min-height / 1phx; |
45 | |
46 | property <bool> test: |
47 | materialized_max_height == 300 && materialized_min_width == 50 && materialized_min_height == 25 && materialized_max_width > 100000 && |
48 | materialized_rect_max_height == 300 && materialized_rect_min_width == 50 && materialized_rect_min_height == 25 && materialized_rect_max_width > 100000; |
49 | } |
50 | |
51 | /* |
52 | |
53 | ```cpp |
54 | auto handle = TestCase::create(); |
55 | const TestCase &instance = *handle; |
56 | slint_testing::send_mouse_click(&instance, 5., 5.); |
57 | assert_eq(instance.get_materialized_max_height(), 300); |
58 | assert_eq(instance.get_materialized_min_width(), 50); |
59 | assert_eq(instance.get_materialized_min_height(), 25); |
60 | // FIXME! float max is overflowing on int |
61 | assert_eq(uint32_t(instance.get_materialized_max_width()), uint32_t(std::numeric_limits<int>::max()) + 1); |
62 | |
63 | assert_eq(instance.get_materialized_rect_max_height(), 300); |
64 | assert_eq(instance.get_materialized_rect_min_width(), 50); |
65 | assert_eq(instance.get_materialized_rect_min_height(), 25); |
66 | // FIXME! float max is overflowing on int |
67 | assert_eq(uint32_t(instance.get_materialized_rect_max_width()), uint32_t(std::numeric_limits<int>::max()) + 1); |
68 | ``` |
69 | |
70 | |
71 | ```rust |
72 | let instance = TestCase::new().unwrap(); |
73 | slint_testing::send_mouse_click(&instance, 5., 5.); |
74 | assert_eq!(instance.get_materialized_max_height(), 300); |
75 | assert_eq!(instance.get_materialized_min_width(), 50); |
76 | assert_eq!(instance.get_materialized_min_height(), 25); |
77 | assert_eq!(instance.get_materialized_max_width(), i32::MAX); |
78 | |
79 | assert_eq!(instance.get_materialized_rect_max_height(), 300); |
80 | assert_eq!(instance.get_materialized_rect_min_width(), 50); |
81 | assert_eq!(instance.get_materialized_rect_min_height(), 25); |
82 | assert_eq!(instance.get_materialized_rect_max_width(), i32::MAX); |
83 | |
84 | ``` |
85 | |
86 | ```js |
87 | var instance = new slint.TestCase(); |
88 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
89 | assert.equal(instance.materialized_max_height, 300); |
90 | assert.equal(instance.materialized_min_width, 50); |
91 | assert.equal(instance.materialized_min_height, 25); |
92 | assert.equal(instance.materialized_max_width, Math.pow(2, 31) - 1); |
93 | |
94 | assert.equal(instance.materialized_rect_max_height, 300); |
95 | assert.equal(instance.materialized_rect_min_width, 50); |
96 | assert.equal(instance.materialized_rect_min_height, 25); |
97 | assert.equal(instance.materialized_rect_max_width, Math.pow(2, 31) - 1); |
98 | ``` |
99 | |
100 | */ |
101 | } |
102 | |
103 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
104 | use i_slint_backend_testing as slint_testing; |
105 | slint_testing::init(); |
106 | let instance = TestCase::new().unwrap(); |
107 | slint_testing::send_mouse_click(&instance, x:5., y:5.); |
108 | assert_eq!(instance.get_materialized_max_height(), 300); |
109 | assert_eq!(instance.get_materialized_min_width(), 50); |
110 | assert_eq!(instance.get_materialized_min_height(), 25); |
111 | assert_eq!(instance.get_materialized_max_width(), i32::MAX); |
112 | |
113 | assert_eq!(instance.get_materialized_rect_max_height(), 300); |
114 | assert_eq!(instance.get_materialized_rect_min_width(), 50); |
115 | assert_eq!(instance.get_materialized_rect_min_height(), 25); |
116 | assert_eq!(instance.get_materialized_rect_max_width(), i32::MAX); |
117 | |
118 | Ok(()) |
119 | } |