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
4// FIXME: Skip embedding test on C++ and NodeJS since ComponentFactory is not implemented there!
5//ignore: cpp,js
6
7export 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
22use slint::ComponentHandle;
23let inner_instance = std::rc::Rc::<core::cell::RefCell<Option<slint_interpreter::ComponentInstance>>>::default();
24let inner_instance_clone = inner_instance.clone();
25let factory = slint::ComponentFactory::new(move |ctx| {
26 let mut compiler = slint_interpreter::ComponentCompiler::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 )).unwrap_or_else(|| panic!("compile error {:?}", compiler.diagnostics()));
43
44 let inner = e.create_embedded(ctx).unwrap();
45 inner_instance_clone.replace(Some(inner.clone_strong()));
46 Some(inner)
47});
48
49let instance = TestCase::new().unwrap();
50instance.set_component_factory(factory.clone());
51assert_eq!(instance.get_pref_height(), 42.);
52let cursor = inner_instance.borrow().as_ref().expect("should have been created").get_property("cursor").unwrap();
53assert_eq!(cursor, slint_interpreter::Value::from(2.));
54```
55
56
57*/
58