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 | export component TestCase inherits Window { |
6 | width: 200px; |
7 | min-height: 300px; |
8 | VerticalLayout { |
9 | HorizontalLayout { |
10 | green := Rectangle { |
11 | background: Colors.green; |
12 | width: 100px; |
13 | } |
14 | red := Rectangle { background: Colors.red; } |
15 | } |
16 | Rectangle { background: orange; } |
17 | } |
18 | |
19 | out property <length> win_w: root.width; |
20 | out property <length> win_h: root.height; |
21 | out property <length> green_w: green.width; |
22 | out property <length> red_w: red.width; |
23 | |
24 | |
25 | out property <bool> test: root.min-height == 300px && root.width == 200px && green.width == 100px && red.width == 100px; |
26 | } |
27 | |
28 | /* |
29 | |
30 | ```cpp |
31 | auto handle = TestCase::create(); |
32 | TestCase &instance = *handle; |
33 | instance.show(); |
34 | assert(instance.get_test()); |
35 | auto size = instance.window().size(); |
36 | assert(size == slint::PhysicalSize({200, 300})); |
37 | assert_eq(instance.get_win_h(), 300.); |
38 | assert_eq(instance.get_win_w(), 200.); |
39 | assert_eq(instance.get_green_w(), 100.); |
40 | assert_eq(instance.get_red_w(), 100.); |
41 | instance.window().set_size(slint::PhysicalSize({150, 150})); |
42 | assert_eq(instance.get_win_h(), 150.); // this didn't have a fixed sized, so the size follow (FIXME: it probably shouldn't) |
43 | assert_eq(instance.get_win_w(), 200.); // but because we have a fixed sized, the geometry don't change |
44 | assert_eq(instance.get_green_w(), 100.); |
45 | assert_eq(instance.get_red_w(), 100.); |
46 | |
47 | ``` |
48 | |
49 | |
50 | ```rust |
51 | let instance = TestCase::new().unwrap(); |
52 | instance.show().unwrap(); |
53 | assert!(instance.get_test()); |
54 | let size = instance.window().size(); |
55 | assert_eq!(size, slint::PhysicalSize::new(200, 300)); |
56 | assert_eq!(instance.get_win_h(), 300.); |
57 | assert_eq!(instance.get_win_w(), 200.); |
58 | assert_eq!(instance.get_green_w(), 100.); |
59 | assert_eq!(instance.get_red_w(), 100.); |
60 | instance.window().set_size(slint::PhysicalSize::new(150, 150)); |
61 | assert_eq!(instance.get_win_h(), 150.); // this didn't have a fixed sized, so the size follow (FIXME: it probably shouldn't) |
62 | assert_eq!(instance.get_win_w(), 200.); // but because we have a fixed sized, the geometry don't change |
63 | assert_eq!(instance.get_green_w(), 100.); |
64 | assert_eq!(instance.get_red_w(), 100.); |
65 | ``` |
66 | |
67 | |
68 | */ |
69 | } |
70 | |
71 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
72 | use i_slint_backend_testing as slint_testing; |
73 | slint_testing::init(); |
74 | let instance = TestCase::new().unwrap(); |
75 | instance.show().unwrap(); |
76 | assert!(instance.get_test()); |
77 | let size = instance.window().size(); |
78 | assert_eq!(size, slint::PhysicalSize::new(200, 300)); |
79 | assert_eq!(instance.get_win_h(), 300.); |
80 | assert_eq!(instance.get_win_w(), 200.); |
81 | assert_eq!(instance.get_green_w(), 100.); |
82 | assert_eq!(instance.get_red_w(), 100.); |
83 | instance.window().set_size(slint::PhysicalSize::new(width:150, height:150)); |
84 | assert_eq!(instance.get_win_h(), 150.); // this didn't have a fixed sized, so the size follow (FIXME: it probably shouldn't) |
85 | assert_eq!(instance.get_win_w(), 200.); // but because we have a fixed sized, the geometry don't change |
86 | assert_eq!(instance.get_green_w(), 100.); |
87 | assert_eq!(instance.get_red_w(), 100.); |
88 | Ok(()) |
89 | } |