|
| 1 | +// Copyright © SixtyFPS GmbH <[email protected]> |
| 2 | +// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | + |
| 4 | +TestCase := Window { |
| 5 | + preferred-width: 500px; |
| 6 | + preferred-height: 500px; |
| 7 | + no-frame: false; |
| 8 | + |
| 9 | + f := Flickable { |
| 10 | + x: 10px; |
| 11 | + y: 10px; |
| 12 | + width: parent.width - 20px; |
| 13 | + height: parent.height - 20px; |
| 14 | + viewport_width: 2100px; |
| 15 | + viewport_height: 2100px; |
| 16 | + |
| 17 | + VerticalLayout { |
| 18 | + padding: 0; |
| 19 | + Rectangle { |
| 20 | + width: 100%; |
| 21 | + height: 20px; |
| 22 | + } |
| 23 | + |
| 24 | + HorizontalLayout { |
| 25 | + Rectangle { |
| 26 | + width: 20px; |
| 27 | + height: 100%; |
| 28 | + } |
| 29 | + |
| 30 | + inner_ta := TouchArea { |
| 31 | + width: 50px; |
| 32 | + height: 50px; |
| 33 | + fs := FocusScope { |
| 34 | + Rectangle { } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + public function set-focus() { |
| 42 | + fs.focus(); |
| 43 | + } |
| 44 | + public function remove-focus() { |
| 45 | + fs.clear-focus(); |
| 46 | + } |
| 47 | + |
| 48 | + property <length> offset_x: -f.viewport_x; |
| 49 | + property <length> offset_y: -f.viewport_y; |
| 50 | +} |
| 51 | + |
| 52 | +/* |
| 53 | +```rust |
| 54 | +// Test that focused items stay visible when resizing the window |
| 55 | +
|
| 56 | +use slint::{LogicalSize, LogicalPosition, platform::WindowEvent}; |
| 57 | +let instance = TestCase::new().unwrap(); |
| 58 | +instance.window().dispatch_event(WindowEvent::Resized { size: LogicalSize::new(70., 70.) }); |
| 59 | +assert_eq!(instance.get_offset_x(), 0.); |
| 60 | +assert_eq!(instance.get_offset_y(), 0.); |
| 61 | +instance.window().dispatch_event(WindowEvent::Resized { size: LogicalSize::new(500., 500.) }); |
| 62 | +assert_eq!(instance.get_offset_x(), 0.); |
| 63 | +assert_eq!(instance.get_offset_y(), 0.); |
| 64 | +instance.invoke_set_focus(); |
| 65 | +instance.window().dispatch_event(WindowEvent::Resized { size: LogicalSize::new(70., 70.) }); |
| 66 | +assert_eq!(instance.get_offset_x(), 20.); |
| 67 | +assert_eq!(instance.get_offset_y(), 20.); |
| 68 | +
|
| 69 | +// Test that items that gain focus scroll to visible |
| 70 | +
|
| 71 | +instance.invoke_remove_focus(); |
| 72 | +instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 20.0, delta_y: 20.0 }); |
| 73 | +assert_eq!(instance.get_offset_x(), 0.); |
| 74 | +assert_eq!(instance.get_offset_y(), 0.); |
| 75 | +instance.invoke_set_focus(); |
| 76 | +assert_eq!(instance.get_offset_x(), 20.); |
| 77 | +assert_eq!(instance.get_offset_y(), 20.); |
| 78 | +
|
| 79 | +``` |
| 80 | +*/ |
0 commit comments