| 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 | TestCase := TextInput { |
| 5 | width: 100phx; |
| 6 | height: 100phx; |
| 7 | property<string> test_text: self.text; |
| 8 | property<int> test_cursor_pos: self.cursor_position_byte_offset; |
| 9 | property<int> test_anchor_pos: self.anchor_position_byte_offset; |
| 10 | property<bool> has_selection: self.test_cursor_pos != self.test_anchor_pos; |
| 11 | property<bool> input_focused: self.has_focus; |
| 12 | } |
| 13 | |
| 14 | /* |
| 15 | ```rust |
| 16 | use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition}; |
| 17 | |
| 18 | let instance = TestCase::new().unwrap(); |
| 19 | slint_testing::send_mouse_click(&instance, 50., 50.); |
| 20 | assert!(instance.get_input_focused()); |
| 21 | assert_eq!(instance.get_test_text(), ""); |
| 22 | slint_testing::send_keyboard_string_sequence(&instance, "Hello World"); |
| 23 | assert_eq!(instance.get_test_text(), "Hello World"); |
| 24 | assert!(!instance.get_has_selection()); |
| 25 | |
| 26 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
| 27 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
| 28 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
| 29 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
| 30 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
| 31 | assert!(instance.get_has_selection()); |
| 32 | assert_eq!(instance.get_test_cursor_pos(), 11); |
| 33 | assert_eq!(instance.get_test_anchor_pos(), 0); |
| 34 | |
| 35 | slint_testing::send_keyboard_string_sequence(&instance, "-"); |
| 36 | assert_eq!(instance.get_test_text(), "-"); |
| 37 | ``` |
| 38 | */ |
| 39 | |