| 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 implemented there! |
| 5 | //ignore: cpp,js |
| 6 | |
| 7 | export component TestCase { |
| 8 | HorizontalLayout { |
| 9 | cont := ComponentContainer { } |
| 10 | } |
| 11 | in property<component-factory> component-factory <=> cont.component-factory; |
| 12 | out property<length> pref-height: root.preferred-height; |
| 13 | } |
| 14 | |
| 15 | /* |
| 16 | |
| 17 | |
| 18 | |
| 19 | ```rust |
| 20 | |
| 21 | // Test that it doesn't panic when we have some focus things in the init callback |
| 22 | use slint::ComponentHandle; |
| 23 | let inner_instance = std::rc::Rc::<core::cell::RefCell<Option<slint_interpreter::ComponentInstance>>>::default(); |
| 24 | let inner_instance_clone = inner_instance.clone(); |
| 25 | let factory = slint::ComponentFactory::new(move |ctx| { |
| 26 | let compiler = slint_interpreter::Compiler::new(); |
| 27 | let e = spin_on::spin_on(compiler.build_from_source( |
| 28 | r#"export component Inner { |
| 29 | preferred-height: 42px; |
| 30 | forward-focus: b; |
| 31 | b := TextInput { |
| 32 | text: "Hello 🌍"; |
| 33 | } |
| 34 | init => { |
| 35 | b.focus(); |
| 36 | b.select_all(); |
| 37 | b.set-selection-offsets(2, 2); |
| 38 | } |
| 39 | out property cursor <=> b.cursor_position_byte_offset ; |
| 40 | }"#.into(), |
| 41 | std::path::PathBuf::from("embedded.slint"), |
| 42 | )).component("Inner").unwrap(); |
| 43 | |
| 44 | let inner = e.create_embedded(ctx).unwrap(); |
| 45 | inner_instance_clone.replace(Some(inner.clone_strong())); |
| 46 | Some(inner) |
| 47 | }); |
| 48 | |
| 49 | let instance = TestCase::new().unwrap(); |
| 50 | instance.set_component_factory(factory.clone()); |
| 51 | assert_eq!(instance.get_pref_height(), 42.); |
| 52 | let cursor = inner_instance.borrow().as_ref().expect("should have been created").get_property("cursor").unwrap(); |
| 53 | assert_eq!(cursor, slint_interpreter::Value::from(2.)); |
| 54 | ``` |
| 55 | |
| 56 | |
| 57 | */ |
| 58 | |