1
2// Copyright © SixtyFPS GmbH <info@slint.dev>
3// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
4
5import { AboutSlint, Button } from "std-widgets.slint";
6import { MenuBorder } from "../../../internal/compiler/widgets/fluent/components.slint";
7export component TestCase inherits Window {
8 width: 300px;
9 height: 300px;
10
11 in-out property <string> result;
12
13 MenuBar {
14 Menu {
15 title: "File";
16 MenuSeparator {} // should be hidden
17 MenuItem {
18 title: "New";
19 activated => { result += self.title; debug("New"); }
20 }
21 MenuItem {
22 title: "Open";
23 activated => { debug("Open"); }
24 }
25 Menu {
26 function open-recent(entry: string) {
27 result += entry;
28 debug(entry);
29 }
30 title: "Open Recent";
31 MenuItem {
32 title: "Recent 1";
33 activated => { open-recent("Recent 1"); }
34 }
35 MenuItem {
36 title: "Recent 2";
37 activated => { open-recent("Recent 2"); }
38 }
39 MenuItem {
40 title: "Recent 3";
41 activated => { open-recent("Recent 3"); }
42 }
43 }
44 MenuSeparator {}
45 MenuSeparator {}
46 MenuItem {
47 title: "Save";
48 activated => { debug("Save"); }
49 }
50 }
51 Menu {
52 title: "Edit";
53 MenuItem {
54 title: "Copy";
55 activated => { debug("Copy"); }
56 }
57 MenuItem {
58 title: "Paste";
59 activated => { debug("Paste"); }
60 }
61 }
62 }
63 vl := VerticalLayout {
64 AboutSlint {}
65 Button { text: "Hello"; }
66 }
67
68 out property <bool> check-geometry: vl.x == 0 && vl.y == 0 && vl.width == root.width && vl.height == root.height;
69
70 out property <bool> test: check-geometry;
71}
72
73/*
74```rust
75use slint::{SharedString, platform::{Key}};
76let instance = TestCase::new().unwrap();
77assert!(instance.get_test());
78// click on the file menu
79slint_testing::send_mouse_click(&instance, 10., 16.);
80// navigate using the keys to the "Open Recent" menu item
81slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
82slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
83slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
84slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::RightArrow));
85slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
86assert_eq!(instance.get_result(), "");
87slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n"));
88assert_eq!(instance.get_result(), "Recent 3");
89
90instance.set_result("".into());
91//click on the file menu
92slint_testing::send_mouse_click(&instance, 10., 16.);
93assert_eq!(instance.get_result(), "");
94// click on the first entry (new) (this value seems to work with all styles)
95slint_testing::send_mouse_click(&instance, 30., 49.);
96assert_eq!(instance.get_result(), "New");
97```
98
99```cpp
100auto handle = TestCase::create();
101const TestCase &instance = *handle;
102assert(instance.get_test());
103// click on the file menu
104slint_testing::send_mouse_click(&instance, 10., 16.);
105// navigate using the keys to the "Open Recent" menu item
106slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
107slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
108slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
109slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::RightArrow);
110slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow);
111assert_eq(instance.get_result(), "");
112slint_testing::send_keyboard_string_sequence(&instance, "\n");
113assert_eq(instance.get_result(), "Recent 3");
114
115instance.set_result("");
116//click on the file menu
117slint_testing::send_mouse_click(&instance, 10., 16.);
118assert_eq(instance.get_result(), "");
119// click on the first entry (new) (this value seems to work with all styles)
120slint_testing::send_mouse_click(&instance, 30., 49.);
121assert_eq(instance.get_result(), "New");
122```
123*/
124