| 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 | |
| 5 | import { AboutSlint, Button } from "std-widgets.slint" ; |
| 6 | import { MenuBorder } from "../../../internal/compiler/widgets/fluent/components.slint" ; |
| 7 | export 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 |
| 75 | use slint::{SharedString, platform::{Key}}; |
| 76 | let instance = TestCase::new().unwrap(); |
| 77 | assert!(instance.get_test()); |
| 78 | // click on the file menu |
| 79 | slint_testing::send_mouse_click(&instance, 10., 16.); |
| 80 | // navigate using the keys to the "Open Recent" menu item |
| 81 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 82 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 83 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 84 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::RightArrow)); |
| 85 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow)); |
| 86 | assert_eq!(instance.get_result(), ""); |
| 87 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n")); |
| 88 | assert_eq!(instance.get_result(), "Recent 3"); |
| 89 | |
| 90 | instance.set_result("".into()); |
| 91 | //click on the file menu |
| 92 | slint_testing::send_mouse_click(&instance, 10., 16.); |
| 93 | assert_eq!(instance.get_result(), ""); |
| 94 | // click on the first entry (new) (this value seems to work with all styles) |
| 95 | slint_testing::send_mouse_click(&instance, 30., 49.); |
| 96 | assert_eq!(instance.get_result(), "New"); |
| 97 | ``` |
| 98 | |
| 99 | ```cpp |
| 100 | auto handle = TestCase::create(); |
| 101 | const TestCase &instance = *handle; |
| 102 | assert(instance.get_test()); |
| 103 | // click on the file menu |
| 104 | slint_testing::send_mouse_click(&instance, 10., 16.); |
| 105 | // navigate using the keys to the "Open Recent" menu item |
| 106 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 107 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 108 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 109 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::RightArrow); |
| 110 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow); |
| 111 | assert_eq(instance.get_result(), ""); |
| 112 | slint_testing::send_keyboard_string_sequence(&instance, "\n"); |
| 113 | assert_eq(instance.get_result(), "Recent 3"); |
| 114 | |
| 115 | instance.set_result(""); |
| 116 | //click on the file menu |
| 117 | slint_testing::send_mouse_click(&instance, 10., 16.); |
| 118 | assert_eq(instance.get_result(), ""); |
| 119 | // click on the first entry (new) (this value seems to work with all styles) |
| 120 | slint_testing::send_mouse_click(&instance, 30., 49.); |
| 121 | assert_eq(instance.get_result(), "New"); |
| 122 | ``` |
| 123 | */ |
| 124 | |