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
12import { ListView } from "std-widgets.slint";
13
14TestCase := 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
39auto handle = TestCase::create();
40const TestCase &instance = *handle;
41
42// Send an initial click to traverse the item tree and force a listview
43// layout.
44slint_testing::send_mouse_click(&instance, 5., 5.);
45assert_eq(instance.get_viewport_height(), 100.);
46
47// Trigger the mouse area to change the model
48slint_testing::send_mouse_click(&instance, 5., 55.);
49
50// Send a second click to force an item tree traversal and listview update
51slint_testing::send_mouse_click(&instance, 5., 5.);
52assert_eq(instance.get_viewport_height(), 200.);
53```
54
55
56```rust
57let instance = TestCase::new().unwrap();
58
59// Send an initial click to traverse the item tree and force a listview
60// layout.
61slint_testing::send_mouse_click(&instance, 5., 5.);
62assert_eq!(instance.get_viewport_height(), 100.);
63
64// Trigger the mouse area to change the model
65slint_testing::send_mouse_click(&instance, 5., 55.);
66
67// Send a second click to force an item tree traversal and listview update
68slint_testing::send_mouse_click(&instance, 5., 5.);
69assert_eq!(instance.get_viewport_height(), 200.);
70```
71
72```js
73var instance = new slint.TestCase();
74
75// Send an initial click to traverse the item tree and force a listview
76// layout.
77slintlib.private_api.send_mouse_click(instance, 5., 5.);
78assert.equal(instance.viewport_height, 100.);
79
80// Trigger the mouse area to change the model
81slintlib.private_api.send_mouse_click(instance, 5., 55.);
82
83// Send a second click to force an item tree traversal and listview update
84slintlib.private_api.send_mouse_click(instance, 5., 5.);
85assert.equal(instance.viewport_height, 200.);
86```
87*/
88