| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | // This test case verifies that the listview updates its layout / geometry when the |
| 5 | // entire model changes. This test works by triggering layout updates by simulating |
| 6 | // mouse clicks, which results in item tree traversal and ensure_updated_listview |
| 7 | // calls, similar to when painting. The actual model change is triggered via simulated |
| 8 | // mouse clicks into the touch area further down. |
| 9 | // Note: The C++ test uses the same test method, but due to its differing implementation |
| 10 | // it's not testing the same code path. |
| 11 | |
| 12 | import { ListView } from "std-widgets.slint" ; |
| 13 | |
| 14 | export component TestCase inherits Window { |
| 15 | width: 300px; |
| 16 | height: 300px; |
| 17 | |
| 18 | in-out property pos <=> lv.viewport-y; |
| 19 | out property <int> clicked-idx: -1; |
| 20 | in-out property<[color]> the_model: [Colors.red, Colors.blue, Colors.yellow, Colors.pink, Colors.orange, Colors.aliceblue, Colors.limegreen]; |
| 21 | lv := ListView { |
| 22 | for col[idx] in the_model: Rectangle { |
| 23 | height: 100px; |
| 24 | background: col; |
| 25 | TouchArea { |
| 26 | clicked => { |
| 27 | clicked-idx = idx; |
| 28 | the_model = [Colors.gray]; |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | |
| 36 | /* |
| 37 | ```cpp |
| 38 | auto handle = TestCase::create(); |
| 39 | const TestCase &instance = *handle; |
| 40 | |
| 41 | |
| 42 | instance.set_pos(-400.); |
| 43 | |
| 44 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 45 | assert_eq(instance.get_clicked_idx(), 4); |
| 46 | |
| 47 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 48 | ``` |
| 49 | |
| 50 | ```rust |
| 51 | let instance = TestCase::new().unwrap(); |
| 52 | |
| 53 | instance.set_pos(-400.); |
| 54 | |
| 55 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 56 | assert_eq!(instance.get_clicked_idx(), 4); |
| 57 | |
| 58 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 59 | assert_eq!(instance.get_clicked_idx(), 0); |
| 60 | ``` |
| 61 | |
| 62 | */ |
| 63 | |