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
6FixedWidthtImage := Image {
7 source: @image-url("cat.jpg");
8 width: 500phx;
9}
10
11TestCase := 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
62auto handle = TestCase::create();
63const TestCase &instance = *handle;
64assert(instance.get_fixed_image_default_image_fit_ok());
65assert(instance.get_fixed_image_image_fit_override_ok());
66assert(instance.get_image_in_layout_fit_ok());
67assert(instance.get_image_in_layout_custom_fit_ok());
68assert(instance.get_image_with_missing_height_ok());
69assert(instance.get_image_with_missing_width_ok());
70assert(instance.get_image_with_missing_width_clipped_ok());
71```
72
73
74```rust
75let instance = TestCase::new().unwrap();
76assert!(instance.get_fixed_image_default_image_fit_ok());
77assert!(instance.get_fixed_image_image_fit_override_ok());
78assert!(instance.get_image_in_layout_fit_ok());
79assert!(instance.get_image_in_layout_custom_fit_ok());
80assert!(instance.get_image_with_missing_height_ok());
81assert!(instance.get_image_with_missing_width_ok());
82assert!(instance.get_image_with_missing_width_clipped_ok());
83```
84
85```js
86var instance = new slint.TestCase();
87assert(instance.fixed_image_default_image_fit_ok);
88assert(instance.fixed_image_image_fit_override_ok);
89assert(instance.image_in_layout_fit_ok);
90assert(instance.image_in_layout_custom_fit_ok);
91assert(instance.image_with_missing_height_ok);
92assert(instance.image_with_missing_width_ok);
93assert(instance.image_with_missing_width_clipped_ok);
94```
95
96*/
97