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
4import { ListView } from "std-widgets.slint";
5
6TestCase := Window {
7 width: 400px;
8 height: 540px;
9
10 in-out property <string> value;
11 out property listview-viewport-height <=> listview.viewport-height;
12 out property listview-viewport-width <=> listview.viewport-width;
13 out property listview-preferred-height <=> listview.preferred-height;
14
15 out property <bool> test: true;
16
17
18
19 listview := ListView {
20 for data in [
21 { text: "Blue", color: #0000ff, bg: #eeeeee},
22 { text: "Red", color: #ff0000, bg: #eeeeee},
23 { text: "Green", color: #00ff00, bg: #eeeeee},
24 { text: "Yellow", color: #ffff00, bg: #222222 },
25 { text: "Black", color: #000000, bg: #eeeeee },
26 { text: "White", color: #ffffff, bg: #222222 },
27 { text: "Magenta", color: #ff00ff, bg: #eeeeee },
28 { text: "Cyan", color: #00ffff, bg: #222222 },
29 ] : delegate := Rectangle {
30 background: @linear-gradient(90deg, data.bg,data.bg.brighter(0.5));
31 HorizontalLayout {
32 text_Name := Text {
33 height: 100px;
34 text: data.text;
35 color: data.color;
36 font_size: 20px ;
37 min-width: 1500px;
38 }
39 }
40 TouchArea { clicked => { value = data.text; } }
41 }
42 }
43}
44
45/*
46```cpp
47auto handle = TestCase::create();
48const TestCase &instance = *handle;
49slint_testing::send_mouse_click(&instance, 5., 205.);
50assert_eq(instance.get_value(), "Green");
51assert(instance.get_test());
52assert_eq(instance.get_listview_viewport_height(), 8. * 100.);
53assert_eq(instance.get_listview_viewport_width(), 1500.);
54
55// scroll all the way down with the mouse wheel and click on the last item
56for (int i = 0; i < 10; ++i) {
57 instance.window().dispatch_pointer_scroll_event(slint::LogicalPosition({25.0, 105.0}), 0, -50);
58}
59slint_testing::send_mouse_click(&instance, 5., 441.);
60assert_eq(instance.get_value(), "Cyan");
61```
62
63```rust
64let instance = TestCase::new().unwrap();
65slint_testing::send_mouse_click(&instance, 5., 205.);
66assert_eq!(instance.get_value(), "Green");
67assert!(instance.get_test());
68assert_eq!(instance.get_listview_viewport_height(), 8. * 100.);
69assert_eq!(instance.get_listview_viewport_width(), 1500.);
70
71// scroll all the way down with the mouse wheel and click on the last item
72use slint::{LogicalPosition, platform::WindowEvent };
73for _ in 0..10 {
74 instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 105.0), delta_x: 0.0, delta_y: -50.0 });
75}
76slint_testing::send_mouse_click(&instance, 5., 441.);
77assert_eq!(instance.get_value(), "Cyan");
78
79```
80
81```js
82var instance = new slint.TestCase();
83slintlib.private_api.send_mouse_click(instance, 5., 205.);
84assert.equal(instance.value, "Green");
85assert(instance.test);
86assert.equal(instance.listview_viewport_height, 8. * 100.);
87assert.equal(instance.listview_viewport_width, 1500.);
88```
89
90*/
91