| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | // FIXME: Skip embedding test on C++ and NodeJS since ComponentFactory is not |
| 5 | // implemented there! |
| 6 | //ignore: cpp,js |
| 7 | |
| 8 | import { Button } from "std-widgets.slint" ; |
| 9 | |
| 10 | component Container { |
| 11 | in property<component-factory> c1 <=> cont1.component-factory; |
| 12 | |
| 13 | cont1 := ComponentContainer { } |
| 14 | } |
| 15 | |
| 16 | export component TestCase inherits Rectangle { |
| 17 | |
| 18 | in property<component-factory> c1; |
| 19 | out property<bool> outside-focus <=> outside.has-focus; |
| 20 | |
| 21 | outside := Button { text: "Outside button" ; } |
| 22 | |
| 23 | Container { |
| 24 | c1 <=> root.c1; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /* |
| 29 | ```cpp |
| 30 | // ComponentFactory not supported yet! |
| 31 | ``` |
| 32 | |
| 33 | ```rust |
| 34 | let factory = slint::ComponentFactory::new(|ctx| { |
| 35 | |
| 36 | let compiler = slint_interpreter::Compiler::new(); |
| 37 | let e = spin_on::spin_on(compiler.build_from_source( |
| 38 | r#"import { Button } from "std-widgets.slint"; |
| 39 | |
| 40 | export component E1 inherits Rectangle { |
| 41 | background: Colors.red; |
| 42 | forward-focus: b; |
| 43 | b := Button { |
| 44 | text: "red"; |
| 45 | } |
| 46 | }"#.into(), |
| 47 | std::path::PathBuf::from("embedded.slint"), |
| 48 | )).component("E1").unwrap(); |
| 49 | e.create_embedded(ctx).ok() |
| 50 | }); |
| 51 | |
| 52 | let instance = TestCase::new().unwrap(); |
| 53 | assert!(!instance.get_outside_focus()); // Nothing has focus be default |
| 54 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
| 55 | assert!(instance.get_outside_focus()); // The outside button is the only thing |
| 56 | // accepting focus at this point. |
| 57 | |
| 58 | instance.set_c1(factory); |
| 59 | |
| 60 | assert!(instance.get_outside_focus()); // embedding does not move the focus |
| 61 | |
| 62 | // focus the two embedded buttons: |
| 63 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
| 64 | assert!(!instance.get_outside_focus()); |
| 65 | |
| 66 | // Go back to outside button |
| 67 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
| 68 | assert!(instance.get_outside_focus()); |
| 69 | |
| 70 | // Focus backwards over the embedded buttons |
| 71 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
| 72 | assert!(!instance.get_outside_focus()); |
| 73 | |
| 74 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
| 75 | assert!(instance.get_outside_focus()); |
| 76 | ``` |
| 77 | |
| 78 | ```js |
| 79 | var _instance = new slint.TestCase(); |
| 80 | ``` |
| 81 | */ |
| 82 | |