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
4import { StandardListView } from "std-widgets.slint";
5
6TestCase := 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
36let instance = TestCase::new().unwrap();
37assert_eq!(instance.get_count(), 3);
38assert_eq!(instance.get_current_item(), -1);
39
40assert_eq!(instance.get_callback_current_item(), -1);
41instance.invoke_set_current_item(1);
42assert_eq!(instance.get_callback_current_item(), 1);
43assert_eq!(instance.get_current_item(), 1);
44```
45*/