| 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 | TestCase := Window { |
| 15 | width: 300px; |
| 16 | height: 300px; |
| 17 | |
| 18 | property<length> viewport-height: lv.viewport-height; |
| 19 | property<[length]> fixed-height-model: [100px, 0px]; |
| 20 | |
| 21 | lv := ListView { |
| 22 | for fixed-height in fixed-height-model: Rectangle { |
| 23 | background: blue; |
| 24 | height: fixed-height; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | TouchArea { |
| 29 | y: 50px; |
| 30 | clicked => { |
| 31 | fixed-height-model = [200px]; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | |
| 37 | /* |
| 38 | ```cpp |
| 39 | auto handle = TestCase::create(); |
| 40 | const TestCase &instance = *handle; |
| 41 | |
| 42 | // Send an initial click to traverse the item tree and force a listview |
| 43 | // layout. |
| 44 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 45 | assert_eq(instance.get_viewport_height(), 100.); |
| 46 | |
| 47 | // Trigger the mouse area to change the model |
| 48 | slint_testing::send_mouse_click(&instance, 5., 55.); |
| 49 | |
| 50 | // Send a second click to force an item tree traversal and listview update |
| 51 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 52 | assert_eq(instance.get_viewport_height(), 200.); |
| 53 | ``` |
| 54 | |
| 55 | |
| 56 | ```rust |
| 57 | let instance = TestCase::new().unwrap(); |
| 58 | |
| 59 | // Send an initial click to traverse the item tree and force a listview |
| 60 | // layout. |
| 61 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 62 | assert_eq!(instance.get_viewport_height(), 100.); |
| 63 | |
| 64 | // Trigger the mouse area to change the model |
| 65 | slint_testing::send_mouse_click(&instance, 5., 55.); |
| 66 | |
| 67 | // Send a second click to force an item tree traversal and listview update |
| 68 | slint_testing::send_mouse_click(&instance, 5., 5.); |
| 69 | assert_eq!(instance.get_viewport_height(), 200.); |
| 70 | ``` |
| 71 | |
| 72 | ```js |
| 73 | var instance = new slint.TestCase(); |
| 74 | |
| 75 | // Send an initial click to traverse the item tree and force a listview |
| 76 | // layout. |
| 77 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
| 78 | assert.equal(instance.viewport_height, 100.); |
| 79 | |
| 80 | // Trigger the mouse area to change the model |
| 81 | slintlib.private_api.send_mouse_click(instance, 5., 55.); |
| 82 | |
| 83 | // Send a second click to force an item tree traversal and listview update |
| 84 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
| 85 | assert.equal(instance.viewport_height, 200.); |
| 86 | ``` |
| 87 | */ |
| 88 | |