1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | //include_path: ../../../examples/printerdemo/ui/images/ |
5 | |
6 | FixedWidthtImage := Image { |
7 | source: @image-url("cat.jpg" ); |
8 | width: 500phx; |
9 | } |
10 | |
11 | TestCase := Rectangle { |
12 | fixed_image := Image { |
13 | width: 50phx; |
14 | height: 50phx; |
15 | } |
16 | fixed_image_contain := Image { |
17 | width: 50phx; |
18 | height: 50phx; |
19 | image-fit: contain; |
20 | } |
21 | |
22 | VerticalLayout { |
23 | image_in_layout := Image { |
24 | } |
25 | image_in_layout_with_explicit_fit := Image { |
26 | image-fit: fill; |
27 | } |
28 | } |
29 | |
30 | image_with_missing_height := FixedWidthtImage { |
31 | property <bool> expected_height_ok: self.height == 750phx; |
32 | } |
33 | |
34 | image_with_missing_width := Image { |
35 | source: @image-url("cat.jpg" ); |
36 | height: 600phx; |
37 | property <bool> expected_width_ok: self.width == 400phx; |
38 | } |
39 | |
40 | image_with_missing_width_clipped := Image { |
41 | source: @image-url("cat.jpg" ); |
42 | height: 600phx; |
43 | source-clip-width: 20; |
44 | source-clip-height: 20; |
45 | property <bool> expected_width_ok: self.width == 600phx; |
46 | } |
47 | |
48 | property <bool> fixed_image_default_image_fit_ok: fixed_image.image-fit == ImageFit.fill; |
49 | property <bool> fixed_image_image_fit_override_ok: fixed_image_contain.image-fit == ImageFit.contain; |
50 | property <bool> image_in_layout_fit_ok: image_in_layout.image-fit == ImageFit.contain; |
51 | property <bool> image_in_layout_custom_fit_ok: image_in_layout_with_explicit_fit.image-fit == ImageFit.fill; |
52 | property <bool> image_with_missing_height_ok <=> image_with_missing_height.expected_height_ok; |
53 | property <bool> image_with_missing_width_ok <=> image_with_missing_width.expected_width_ok; |
54 | property <bool> image_with_missing_width_clipped_ok <=> image_with_missing_width.expected_width_ok; |
55 | |
56 | property <bool> test: fixed_image_default_image_fit_ok && fixed_image_image_fit_override_ok && image_in_layout_fit_ok && image_in_layout_custom_fit_ok && image_with_missing_height_ok && image_with_missing_width_ok && image_with_missing_width_clipped_ok; |
57 | } |
58 | |
59 | /* |
60 | |
61 | ```cpp |
62 | auto handle = TestCase::create(); |
63 | const TestCase &instance = *handle; |
64 | assert(instance.get_fixed_image_default_image_fit_ok()); |
65 | assert(instance.get_fixed_image_image_fit_override_ok()); |
66 | assert(instance.get_image_in_layout_fit_ok()); |
67 | assert(instance.get_image_in_layout_custom_fit_ok()); |
68 | assert(instance.get_image_with_missing_height_ok()); |
69 | assert(instance.get_image_with_missing_width_ok()); |
70 | assert(instance.get_image_with_missing_width_clipped_ok()); |
71 | ``` |
72 | |
73 | |
74 | ```rust |
75 | let instance = TestCase::new().unwrap(); |
76 | assert!(instance.get_fixed_image_default_image_fit_ok()); |
77 | assert!(instance.get_fixed_image_image_fit_override_ok()); |
78 | assert!(instance.get_image_in_layout_fit_ok()); |
79 | assert!(instance.get_image_in_layout_custom_fit_ok()); |
80 | assert!(instance.get_image_with_missing_height_ok()); |
81 | assert!(instance.get_image_with_missing_width_ok()); |
82 | assert!(instance.get_image_with_missing_width_clipped_ok()); |
83 | ``` |
84 | |
85 | ```js |
86 | var instance = new slint.TestCase(); |
87 | assert(instance.fixed_image_default_image_fit_ok); |
88 | assert(instance.fixed_image_image_fit_override_ok); |
89 | assert(instance.image_in_layout_fit_ok); |
90 | assert(instance.image_in_layout_custom_fit_ok); |
91 | assert(instance.image_with_missing_height_ok); |
92 | assert(instance.image_with_missing_width_ok); |
93 | assert(instance.image_with_missing_width_clipped_ok); |
94 | ``` |
95 | |
96 | */ |
97 | |