1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/types"# ] |
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 | global SomeGlobal := { |
6 | property<relative-font-size> global_rem: 4rem; |
7 | } |
8 | |
9 | TestCase := Window { |
10 | default-font-size: 10px; |
11 | property<length> normal: 1rem; |
12 | property<length> double: 2rem; |
13 | property<length> half: 0.5rem; |
14 | property <relative-font-size> four_rem: 4rem; |
15 | property<length> four: four_rem; |
16 | |
17 | property<physical-length> phys-pixel-size: 1rem; |
18 | |
19 | property <relative-font-size> px_to_rem: 20px; |
20 | property <relative-font-size> phx_to_rem: 20phx; |
21 | |
22 | property <bool> cmp_test: normal < 1rem && double > 1rem; |
23 | |
24 | property<bool> test:(normal == 10px && double == 20px && half == 5px && four_rem == 40px && SomeGlobal.global_rem == 40px && phys-pixel-size == 10phx && px_to_rem == 2rem); |
25 | } |
26 | |
27 | /* |
28 | |
29 | ```cpp |
30 | auto handle = TestCase::create(); |
31 | const TestCase &instance = *handle; |
32 | assert(instance.get_test()); |
33 | |
34 | assert_eq(instance.get_phx_to_rem(), 2.); |
35 | assert_eq(instance.get_px_to_rem(), 2.); |
36 | instance.window().window_handle().set_scale_factor(2.0); |
37 | assert_eq(instance.get_phys_pixel_size(), 20.); |
38 | assert_eq(instance.get_phx_to_rem(), 1.); |
39 | assert_eq(instance.get_px_to_rem(), 2.); |
40 | ``` |
41 | |
42 | |
43 | ```rust |
44 | let instance = TestCase::new().unwrap(); |
45 | assert!(instance.get_test()); |
46 | |
47 | assert_eq!(instance.get_phx_to_rem(), 2.); |
48 | assert_eq!(instance.get_px_to_rem(), 2.); |
49 | slint_testing::set_window_scale_factor(&instance, 2.0); |
50 | assert_eq!(instance.get_phys_pixel_size(), 20.); |
51 | assert_eq!(instance.get_phx_to_rem(), 1.); |
52 | assert_eq!(instance.get_px_to_rem(), 2.); |
53 | ``` |
54 | |
55 | ```js |
56 | var instance = new slint.TestCase({}); |
57 | assert(instance.test); |
58 | ``` |
59 | |
60 | */ |
61 | } |
62 | |
63 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
64 | use i_slint_backend_testing as slint_testing; |
65 | slint_testing::init(); |
66 | let instance = TestCase::new().unwrap(); |
67 | assert!(instance.get_test()); |
68 | |
69 | assert_eq!(instance.get_phx_to_rem(), 2.); |
70 | assert_eq!(instance.get_px_to_rem(), 2.); |
71 | slint_testing::set_window_scale_factor(&instance, factor:2.0); |
72 | assert_eq!(instance.get_phys_pixel_size(), 20.); |
73 | assert_eq!(instance.get_phx_to_rem(), 1.); |
74 | assert_eq!(instance.get_px_to_rem(), 2.); |
75 | Ok(()) |
76 | } |