1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | import { StandardListView } from "std-widgets.slint" ; |
5 | |
6 | TestCase := Rectangle { |
7 | callback set-current-item(int); |
8 | |
9 | out property <int> count: list.model.length; |
10 | out property <int> callback-current-item: -1; |
11 | |
12 | in-out property<[StandardListViewItem]> model: [ |
13 | { text: "Item 1" }, |
14 | { text: "Item 2" }, |
15 | { text: "Item 3" }, |
16 | ]; |
17 | in-out property <int> current-item <=> list.current-item; |
18 | |
19 | list := StandardListView { |
20 | model: root.model; |
21 | |
22 | current-item-changed(index) => { |
23 | root.callback-current-item = index; |
24 | } |
25 | } |
26 | |
27 | |
28 | set-current-item(index) => { |
29 | list.set-current-item(index); |
30 | } |
31 | } |
32 | |
33 | /* |
34 | |
35 | ```rust |
36 | let instance = TestCase::new().unwrap(); |
37 | assert_eq!(instance.get_count(), 3); |
38 | assert_eq!(instance.get_current_item(), -1); |
39 | |
40 | assert_eq!(instance.get_callback_current_item(), -1); |
41 | instance.invoke_set_current_item(1); |
42 | assert_eq!(instance.get_callback_current_item(), 1); |
43 | assert_eq!(instance.get_current_item(), 1); |
44 | ``` |
45 | */ |