1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"# ] |
2 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
3 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
4 | |
5 | // FIXME: Skip embedding test on C++ and NodeJS since ComponentFactory is not |
6 | // implemented there! |
7 | //ignore: cpp,js |
8 | |
9 | import { Button } from "std-widgets.slint" ; |
10 | |
11 | export component TestCase inherits Rectangle { |
12 | cont1 := ComponentContainer { } |
13 | |
14 | cont2 := ComponentContainer { } |
15 | |
16 | outside := Button { text: "Outside button" ; } |
17 | |
18 | in property<component-factory> c1 <=> cont1.component-factory; |
19 | in property<component-factory> c2 <=> cont2.component-factory; |
20 | out property<bool> outside-focus <=> outside.has-focus; |
21 | } |
22 | |
23 | /* |
24 | ```cpp |
25 | // ComponentFactory not supported yet! |
26 | ``` |
27 | |
28 | ```rust |
29 | let factory = slint::ComponentFactory::new(|ctx| { |
30 | |
31 | let mut compiler = slint_interpreter::ComponentCompiler::new(); |
32 | let e = spin_on::spin_on(compiler.build_from_source( |
33 | r#"import { Button } from "std-widgets.slint"; |
34 | |
35 | export component E1 inherits Rectangle { |
36 | background: Colors.red; |
37 | forward-focus: b; |
38 | b := Button { |
39 | text: "red"; |
40 | } |
41 | }"#.into(), |
42 | std::path::PathBuf::from("embedded.slint"), |
43 | )).unwrap(); |
44 | e.create_embedded(ctx).ok() |
45 | }); |
46 | |
47 | let instance = TestCase::new().unwrap(); |
48 | assert!(!instance.get_outside_focus()); // Nothing has focus be default |
49 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
50 | assert!(instance.get_outside_focus()); // The outside button is the only thing |
51 | // accepting focus at this point. |
52 | |
53 | instance.set_c1(factory.clone()); |
54 | instance.set_c2(factory); |
55 | |
56 | assert!(instance.get_outside_focus()); // embedding does not move the focus |
57 | |
58 | // focus the two embedded buttons: |
59 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
60 | assert!(!instance.get_outside_focus()); |
61 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
62 | assert!(!instance.get_outside_focus()); |
63 | |
64 | // Go back to outside button |
65 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
66 | assert!(instance.get_outside_focus()); |
67 | |
68 | // Focus backwards over the embedded buttons |
69 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
70 | assert!(!instance.get_outside_focus()); |
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 | } |
83 | |
84 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
85 | use i_slint_backend_testing as slint_testing; |
86 | slint_testing::init(); |
87 | let factory = slint::ComponentFactory::new(|ctx| { |
88 | |
89 | let mut compiler = slint_interpreter::ComponentCompiler::new(); |
90 | let e = spin_on::spin_on(compiler.build_from_source( |
91 | r#"import { Button } from "std-widgets.slint"; |
92 | |
93 | export component E1 inherits Rectangle { |
94 | background: Colors.red; |
95 | forward-focus: b; |
96 | b := Button { |
97 | text: "red"; |
98 | } |
99 | }"# .into(), |
100 | std::path::PathBuf::from("embedded.slint" ), |
101 | )).unwrap(); |
102 | e.create_embedded(ctx).ok() |
103 | }); |
104 | |
105 | let instance = TestCase::new().unwrap(); |
106 | assert!(!instance.get_outside_focus()); // Nothing has focus be default |
107 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
108 | assert!(instance.get_outside_focus()); // The outside button is the only thing |
109 | // accepting focus at this point. |
110 | |
111 | instance.set_c1(factory.clone()); |
112 | instance.set_c2(factory); |
113 | |
114 | assert!(instance.get_outside_focus()); // embedding does not move the focus |
115 | |
116 | // focus the two embedded buttons: |
117 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
118 | assert!(!instance.get_outside_focus()); |
119 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
120 | assert!(!instance.get_outside_focus()); |
121 | |
122 | // Go back to outside button |
123 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
124 | assert!(instance.get_outside_focus()); |
125 | |
126 | // Focus backwards over the embedded buttons |
127 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
128 | assert!(!instance.get_outside_focus()); |
129 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
130 | assert!(!instance.get_outside_focus()); |
131 | |
132 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
133 | assert!(instance.get_outside_focus()); |
134 | Ok(()) |
135 | } |