1 | #![allow (deprecated)]slint::slint!{#[style="cosmic" #] |
2 | #[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/widgets"# ] |
3 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
4 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
5 | |
6 | import { StandardListView } from "std-widgets.slint" ; |
7 | |
8 | TestCase := Rectangle { |
9 | callback set-current-item(int); |
10 | |
11 | out property <int> count: list.model.length; |
12 | out property <int> callback-current-item: -1; |
13 | |
14 | in-out property<[StandardListViewItem]> model: [ |
15 | { text: "Item 1" }, |
16 | { text: "Item 2" }, |
17 | { text: "Item 3" }, |
18 | ]; |
19 | in-out property <int> current-item <=> list.current-item; |
20 | |
21 | list := StandardListView { |
22 | model: root.model; |
23 | |
24 | current-item-changed(index) => { |
25 | root.callback-current-item = index; |
26 | } |
27 | } |
28 | |
29 | |
30 | set-current-item(index) => { |
31 | list.set-current-item(index); |
32 | } |
33 | } |
34 | |
35 | /* |
36 | |
37 | ```rust |
38 | let instance = TestCase::new().unwrap(); |
39 | assert_eq!(instance.get_count(), 3); |
40 | assert_eq!(instance.get_current_item(), -1); |
41 | |
42 | assert_eq!(instance.get_callback_current_item(), -1); |
43 | instance.invoke_set_current_item(1); |
44 | assert_eq!(instance.get_callback_current_item(), 1); |
45 | assert_eq!(instance.get_current_item(), 1); |
46 | ``` |
47 | */} |
48 | |
49 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
50 | use i_slint_backend_testing as slint_testing; |
51 | slint_testing::init(); |
52 | let instance = TestCase::new().unwrap(); |
53 | assert_eq!(instance.get_count(), 3); |
54 | assert_eq!(instance.get_current_item(), -1); |
55 | |
56 | assert_eq!(instance.get_callback_current_item(), -1); |
57 | instance.invoke_set_current_item(1); |
58 | assert_eq!(instance.get_callback_current_item(), 1); |
59 | assert_eq!(instance.get_current_item(), 1); |
60 | Ok(()) |
61 | } |