| 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 | |
| 5 | export X := Rectangle { |
| 6 | forward-focus: someRect; |
| 7 | // ^error{Cannot forward focus to unfocusable element} |
| 8 | |
| 9 | callback trigger_focus_change(); |
| 10 | trigger_focus_change => { |
| 11 | someRect.focus(); |
| 12 | // ^error{focus\(\) can only be called on focusable elements} |
| 13 | } |
| 14 | |
| 15 | indirect_focus_chain_rect := Rectangle { |
| 16 | forward-focus: someRect; |
| 17 | // ^error{Cannot forward focus to unfocusable element} |
| 18 | } |
| 19 | |
| 20 | callback trigger_focus_change_2(); |
| 21 | trigger_focus_change_2 => { |
| 22 | indirect_focus_chain_rect.focus(); |
| 23 | } |
| 24 | |
| 25 | someRect := Rectangle {} |
| 26 | |
| 27 | someFocusScope := FocusScope {} |
| 28 | callback activate_focus_scope(); |
| 29 | activate_focus_scope => { |
| 30 | someFocusScope.focus(); // OK! |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | |
| 35 | |
| 36 | export Y := FocusScope { |
| 37 | forward-focus: self; |
| 38 | // ^error{forward-focus can't refer to itself} |
| 39 | x:= X { } |
| 40 | key-pressed => { |
| 41 | r0.focus(); |
| 42 | x.focus(); |
| 43 | // ^error{focus\(\) can only be called on focusable elements} |
| 44 | accept |
| 45 | } |
| 46 | |
| 47 | r1:= Rectangle { |
| 48 | forward-focus: r2; |
| 49 | // ^error{Cannot forward focus to unfocusable element} |
| 50 | } |
| 51 | r0:= Rectangle { |
| 52 | forward-focus: r1; |
| 53 | // ^error{Cannot forward focus to unfocusable element} |
| 54 | } |
| 55 | r2 := Rectangle { |
| 56 | forward-focus: r3; |
| 57 | // ^error{Cannot forward focus to unfocusable element} |
| 58 | } |
| 59 | r3 := Rectangle { |
| 60 | forward-focus: r1; |
| 61 | // ^error{Cannot forward focus to unfocusable element} |
| 62 | } |
| 63 | } |
| 64 | |