-
Notifications
You must be signed in to change notification settings - Fork 996
Expand file tree
/
Copy pathtextedit.slint
More file actions
124 lines (103 loc) · 5.26 KB
/
Copy pathtextedit.slint
File metadata and controls
124 lines (103 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { TextEdit } from "std-widgets.slint";
export component TestCase inherits Window {
width: 100px;
height: 100px;
edit := TextEdit {
width: 100%;
height: 100%;
}
forward-focus: edit;
out property <bool> textedit-focused <=> edit.has_focus;
callback edited <=> edit.edited;
in-out property <string> text <=> edit.text;
in-out property <bool> read-only <=> edit.read-only;
in-out property <bool> enabled <=> edit.enabled;
public function paste() {
edit.paste();
}
public function cut() {
edit.cut();
}
public function select_all() {
edit.select_all();
}
}
/*
```rust
use std::cell::RefCell;
use std::rc::Rc;
use slint::SharedString;
let instance = TestCase::new().unwrap();
let edits = Rc::new(RefCell::new(Vec::new()));
instance.on_edited({
let edits = edits.clone();
move |val| {
edits.borrow_mut().push(val);
}});
slint_testing::send_mouse_click(&instance, 25., 25.);
assert!(instance.get_textedit_focused());
assert!(edits.borrow().is_empty());
slint_testing::send_keyboard_string_sequence(&instance, "hello");
assert_eq!(edits.borrow().clone(), vec!["h", "he", "hel", "hell", "hello"]);
// Test mouse cursor for issue 6444
use slint::{LogicalPosition, platform::{WindowEvent, PointerEventButton}};
use slint::private_unstable_api::re_exports::MouseCursor;
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text, "after previous click");
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(50.0, 50.0), button: PointerEventButton::Middle });
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text, "Middle button pressed");
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(50.0, 50.0), button: PointerEventButton::Middle });
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text, "Middle button released");
instance.window().dispatch_event(WindowEvent::PointerExited { });
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);
// test page up/down
for x in 0..10 {
slint_testing::send_keyboard_string_sequence(&instance, &format!("\nThis is line {x}"));
}
slint_testing::send_keyboard_string_sequence(&instance, "\nEnd");
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageUp));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageUp));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageUp));
slint_testing::send_keyboard_string_sequence(&instance, "Begin!");
assert_eq!(instance.get_text(), "Begin!hello\nThis is line 0\nThis is line 1\nThis is line 2\nThis is line 3\nThis is line 4\nThis is line 5\nThis is line 6\nThis is line 7\nThis is line 8\nThis is line 9\nEnd");
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageDown));
slint_testing::send_keyboard_string_sequence(&instance, "XX");
let test = instance.get_text();
// The exact position depends on the size of the content which depends on the style, but it should be in the middle
assert!(test.contains("\nThis iXXs line"));
// use the menu key to pen the menu and choose select call
instance.set_text("Hello👋".into());
assert_eq!(instance.get_text(), "Hello👋");
// select all
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::Menu));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::UpArrow));
slint_testing::send_keyboard_string_sequence(&instance, "\n");
assert_eq!(instance.get_text(), "Hello👋");
// copy
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::Menu));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, "\n");
assert_eq!(instance.get_text(), "Hello👋");
slint_testing::send_keyboard_string_sequence(&instance, "Xxx");
assert_eq!(instance.get_text(), "Xxx");
instance.invoke_paste();
assert_eq!(instance.get_text(), "XxxHello👋");
let mut edit_search = slint_testing::ElementHandle::find_by_element_id(&instance, "TestCase::edit");
let edit = edit_search.next().unwrap();
assert_eq!(edit.accessible_read_only(), Some(false));
instance.set_read_only(true);
assert_eq!(edit.accessible_read_only(), Some(true));
instance.set_read_only(true);
instance.invoke_paste();
assert_eq!(instance.get_text(), "XxxHello👋");
instance.set_read_only(false);
instance.set_enabled(false);
instance.invoke_paste();
assert_eq!(instance.get_text(), "XxxHello👋");
instance.invoke_select_all();
instance.invoke_cut();
assert_eq!(instance.get_text(), "XxxHello👋");
```
*/