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 { ComboBox } from "std-widgets.slint";
5export component TestCase inherits Window {
6 width: 200px;
7 height: 200px;
8
9 in-out property <string> output;
10 TouchArea {
11 clicked => { output += "clicked-under\n"; }
12 }
13
14 VerticalLayout {
15 alignment: center;
16 box := ComboBox {
17 model: ["Aaa", "Bbb", "Ccc"];
18 selected => {
19 output += "selected("+self.current-value+","+self.current-index+")\n";
20 }
21 }
22 }
23
24 in-out property current-index <=> box.current-index;
25 in-out property current-value <=> box.current-value;
26 out property has-focus <=> box.has-focus;
27}
28
29/*
30
31
32```rust
33use slint::platform::Key;
34use slint::SharedString;
35
36let instance = TestCase::new().unwrap();
37
38assert_eq!(instance.get_current_value(), "Aaa");
39assert_eq!(instance.get_current_index(), 0);
40assert_eq!(instance.get_has_focus(), false);
41
42// Change the index programmatically
43instance.set_current_index(1);
44assert_eq!(instance.get_current_value(), "Bbb");
45assert_eq!(instance.get_current_index(), 1);
46assert_eq!(instance.get_output(), "");
47instance.set_current_index(0);
48assert_eq!(instance.get_current_value(), "Aaa");
49assert_eq!(instance.get_current_index(), 0);
50assert_eq!(instance.get_output(), "");
51assert_eq!(instance.get_has_focus(), false);
52
53// Open the combobox
54slint_testing::send_mouse_click(&instance, 100., 100.);
55assert_eq!(instance.get_output(), "");
56assert_eq!(instance.get_has_focus(), true);
57
58// click outside of the combobox, this should close it
59slint_testing::send_mouse_click(&instance, 100., 10.);
60assert_eq!(instance.get_output(), "");
61assert_eq!(instance.get_current_value(), "Aaa");
62assert_eq!(instance.get_current_index(), 0);
63assert_eq!(instance.get_has_focus(), true);
64
65// click outside of the combobox again
66slint_testing::send_mouse_click(&instance, 100., 10.);
67assert_eq!(instance.get_output(), "clicked-under\n");
68instance.set_output(Default::default());
69assert_eq!(instance.get_current_value(), "Aaa");
70assert_eq!(instance.get_current_index(), 0);
71assert_eq!(instance.get_has_focus(), true);
72
73
74// The arrow change the values
75slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
76assert_eq!(instance.get_current_value(), "Bbb");
77assert_eq!(instance.get_current_index(), 1);
78assert_eq!(instance.get_output(), "selected(Bbb,1)\n");
79slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
80assert_eq!(instance.get_current_value(), "Ccc");
81assert_eq!(instance.get_current_index(), 2);
82assert_eq!(instance.get_output(), "selected(Bbb,1)\nselected(Ccc,2)\n");
83slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
84assert_eq!(instance.get_current_value(), "Bbb");
85assert_eq!(instance.get_current_index(), 1);
86assert_eq!(instance.get_output(), "selected(Bbb,1)\nselected(Ccc,2)\nselected(Bbb,1)\n");
87instance.set_output(Default::default());
88
89
90```
91
92*/
93