1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/issues"# ] |
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 | // This test case verifies that the listview updates its layout / geometry when the |
6 | // entire model changes. This test works by triggering layout updates by simulating |
7 | // mouse clicks, which results in item tree traversal and ensure_updated_listview |
8 | // calls, similar to when painting. The actual model change is triggered via simulated |
9 | // mouse clicks into the touch area further down. |
10 | // Note: The C++ test uses the same test method, but due to its differing implementation |
11 | // it's not testing the same code path. |
12 | |
13 | import { ListView } from "std-widgets.slint" ; |
14 | |
15 | export component TestCase inherits Window { |
16 | width: 300px; |
17 | height: 300px; |
18 | |
19 | in-out property pos <=> lv.viewport-y; |
20 | out property <int> clicked-idx: -1; |
21 | in-out property<[color]> the_model: [Colors.red, Colors.blue, Colors.yellow, Colors.pink, Colors.orange, Colors.aliceblue, Colors.limegreen]; |
22 | lv := ListView { |
23 | for col[idx] in the_model: Rectangle { |
24 | height: 100px; |
25 | background: col; |
26 | TouchArea { |
27 | clicked => { |
28 | clicked-idx = idx; |
29 | the_model = [Colors.gray]; |
30 | } |
31 | } |
32 | } |
33 | } |
34 | } |
35 | |
36 | |
37 | /* |
38 | ```cpp |
39 | auto handle = TestCase::create(); |
40 | const TestCase &instance = *handle; |
41 | |
42 | |
43 | instance.set_pos(-400.); |
44 | |
45 | slint_testing::send_mouse_click(&instance, 5., 5.); |
46 | assert_eq(instance.get_clicked_idx(), 4); |
47 | |
48 | slint_testing::send_mouse_click(&instance, 5., 5.); |
49 | ``` |
50 | |
51 | ```rust |
52 | let instance = TestCase::new().unwrap(); |
53 | |
54 | instance.set_pos(-400.); |
55 | |
56 | slint_testing::send_mouse_click(&instance, 5., 5.); |
57 | assert_eq!(instance.get_clicked_idx(), 4); |
58 | |
59 | slint_testing::send_mouse_click(&instance, 5., 5.); |
60 | assert_eq!(instance.get_clicked_idx(), 0); |
61 | ``` |
62 | |
63 | */ |
64 | } |
65 | |
66 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
67 | use i_slint_backend_testing as slint_testing; |
68 | slint_testing::init(); |
69 | let instance = TestCase::new().unwrap(); |
70 | |
71 | instance.set_pos(-400.); |
72 | |
73 | slint_testing::send_mouse_click(&instance, x:5., y:5.); |
74 | assert_eq!(instance.get_clicked_idx(), 4); |
75 | |
76 | slint_testing::send_mouse_click(&instance, x:5., y:5.); |
77 | assert_eq!(instance.get_clicked_idx(), 0); |
78 | Ok(()) |
79 | } |