| 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 | import { LineEdit } from "std-widgets.slint" ; |
| 5 | |
| 6 | |
| 7 | component Sub { |
| 8 | in-out property <bool> condition: true; |
| 9 | in property <bool> enabled: true; |
| 10 | callback set-value(string); |
| 11 | if condition : HorizontalLayout { |
| 12 | LineEdit { |
| 13 | accepted => { |
| 14 | set-value(self.text); |
| 15 | } |
| 16 | placeholder-text: "Hello" ; |
| 17 | enabled <=> root.enabled; |
| 18 | } |
| 19 | LineEdit { |
| 20 | enabled <=> root.enabled; |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | component Sub2 { |
| 26 | in property <bool> condition; |
| 27 | in property <bool> enabled: true; |
| 28 | callback focus-c(); |
| 29 | if !condition: VerticalLayout { |
| 30 | if true: LineEdit { enabled <=> root.enabled; } |
| 31 | if !condition: FocusScope { |
| 32 | focus-changed-event => { |
| 33 | focus-c(); |
| 34 | } |
| 35 | enabled <=> root.enabled; |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | export component TestCase inherits Window { |
| 41 | in-out property <bool> condition: true; |
| 42 | |
| 43 | out property <string> value; |
| 44 | |
| 45 | if condition: VerticalLayout { |
| 46 | if true: Sub { |
| 47 | set-value(v) => { value = v; condition = false; } |
| 48 | condition: root.condition; |
| 49 | enabled: root.condition; |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | if true: Sub2 { |
| 55 | condition: root.condition; |
| 56 | focus-c() => { condition = true; } |
| 57 | enabled: !root.condition; |
| 58 | } |
| 59 | |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | ```rust |
| 64 | let instance = TestCase::new().unwrap(); |
| 65 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
| 66 | slint_testing::send_keyboard_string_sequence(&instance, "hophop\n"); |
| 67 | assert_eq!(instance.get_value(), "hophop"); |
| 68 | assert_eq!(instance.get_condition(), false); |
| 69 | slint_testing::send_keyboard_string_sequence(&instance, "a\n\tdd\t\t"); |
| 70 | assert_eq!(instance.get_condition(), true); |
| 71 | slint_testing::send_keyboard_string_sequence(&instance, "\tblop\n\t"); |
| 72 | assert_eq!(instance.get_value(), "blop"); |
| 73 | ``` |
| 74 | |
| 75 | */ |
| 76 | |