1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"# ] |
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 | import { ListView } from "std-widgets.slint" ; |
6 | |
7 | Item := Text { |
8 | property <int> index; |
9 | text: "I'm item #" + index; |
10 | Rectangle { |
11 | border-width: 1px; |
12 | border-color: red; |
13 | } |
14 | } |
15 | |
16 | export TestCase := Window { |
17 | width: 300phx; |
18 | height: 300phx; |
19 | |
20 | property <int> last_clicked: -1; |
21 | |
22 | property <length> item-height: 25phx; |
23 | property <length> listview-y <=> lv.viewport_y; |
24 | |
25 | lv := ListView { |
26 | for i in 200: r := Item { |
27 | index: i; |
28 | height: item-height; |
29 | property <bool> open; |
30 | HorizontalLayout { |
31 | TouchArea { |
32 | clicked => { |
33 | if (open) { |
34 | r.height = item-height; |
35 | open = false; |
36 | } else { |
37 | lv.viewport_y = -r.y; |
38 | r.height = lv.visible-height; |
39 | open = true; |
40 | } |
41 | } |
42 | } |
43 | TouchArea { |
44 | clicked => { |
45 | last-clicked = i; |
46 | } |
47 | } |
48 | } |
49 | } |
50 | } |
51 | } |
52 | |
53 | /* |
54 | ```rust |
55 | let instance = TestCase::new().unwrap(); |
56 | |
57 | // Open the item 6 |
58 | slint_testing::send_mouse_click(&instance, 50., 25. * 6. + 10.); |
59 | slint_testing::send_mouse_click(&instance, 250., 10.); |
60 | assert_eq!(instance.get_last_clicked(), 6); |
61 | instance.set_last_clicked(-1); |
62 | slint_testing::send_mouse_click(&instance, 250., 270.); |
63 | assert_eq!(instance.get_last_clicked(), 6); |
64 | |
65 | // Close the item 6 |
66 | slint_testing::send_mouse_click(&instance, 50., 160.); |
67 | // Item 6 should stay the first, so in position 3 we have the 9th item |
68 | slint_testing::send_mouse_click(&instance, 250., 25. * 3. + 10.); |
69 | assert_eq!(instance.get_last_clicked(), 9); |
70 | |
71 | // Open the 10th item (position 4) |
72 | slint_testing::send_mouse_click(&instance, 50., 25. * 4. + 10.); |
73 | slint_testing::send_mouse_click(&instance, 250., 10.); |
74 | assert_eq!(instance.get_last_clicked(), 10); |
75 | instance.set_last_clicked(-1); |
76 | slint_testing::send_mouse_click(&instance, 250., 270.); |
77 | assert_eq!(instance.get_last_clicked(), 10); |
78 | ``` |
79 | */ |
80 | } |
81 | |
82 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
83 | use i_slint_backend_testing as slint_testing; |
84 | slint_testing::init(); |
85 | let instance = TestCase::new().unwrap(); |
86 | |
87 | // Open the item 6 |
88 | slint_testing::send_mouse_click(&instance, 50., 25. * 6. + 10.); |
89 | slint_testing::send_mouse_click(&instance, 250., 10.); |
90 | assert_eq!(instance.get_last_clicked(), 6); |
91 | instance.set_last_clicked(-1); |
92 | slint_testing::send_mouse_click(&instance, 250., 270.); |
93 | assert_eq!(instance.get_last_clicked(), 6); |
94 | |
95 | // Close the item 6 |
96 | slint_testing::send_mouse_click(&instance, 50., 160.); |
97 | // Item 6 should stay the first, so in position 3 we have the 9th item |
98 | slint_testing::send_mouse_click(&instance, 250., 25. * 3. + 10.); |
99 | assert_eq!(instance.get_last_clicked(), 9); |
100 | |
101 | // Open the 10th item (position 4) |
102 | slint_testing::send_mouse_click(&instance, 50., 25. * 4. + 10.); |
103 | slint_testing::send_mouse_click(&instance, 250., 10.); |
104 | assert_eq!(instance.get_last_clicked(), 10); |
105 | instance.set_last_clicked(-1); |
106 | slint_testing::send_mouse_click(&instance, 250., 270.); |
107 | assert_eq!(instance.get_last_clicked(), 10); |
108 | Ok(()) |
109 | } |