| 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 { ListView } from "std-widgets.slint" ; |
| 5 | |
| 6 | TestCase := Window { |
| 7 | width: 400px; |
| 8 | height: 540px; |
| 9 | |
| 10 | in-out property <string> value; |
| 11 | out property listview-viewport-height <=> listview.viewport-height; |
| 12 | out property listview-viewport-width <=> listview.viewport-width; |
| 13 | out property listview-preferred-height <=> listview.preferred-height; |
| 14 | |
| 15 | out property <bool> test: true; |
| 16 | |
| 17 | |
| 18 | |
| 19 | listview := ListView { |
| 20 | for data in [ |
| 21 | { text: "Blue" , color: #0000ff, bg: #eeeeee}, |
| 22 | { text: "Red" , color: #ff0000, bg: #eeeeee}, |
| 23 | { text: "Green" , color: #00ff00, bg: #eeeeee}, |
| 24 | { text: "Yellow" , color: #ffff00, bg: #222222 }, |
| 25 | { text: "Black" , color: #000000, bg: #eeeeee }, |
| 26 | { text: "White" , color: #ffffff, bg: #222222 }, |
| 27 | { text: "Magenta" , color: #ff00ff, bg: #eeeeee }, |
| 28 | { text: "Cyan" , color: #00ffff, bg: #222222 }, |
| 29 | ] : delegate := Rectangle { |
| 30 | background: @linear-gradient(90deg, data.bg,data.bg.brighter(0.5)); |
| 31 | HorizontalLayout { |
| 32 | text_Name := Text { |
| 33 | height: 100px; |
| 34 | text: data.text; |
| 35 | color: data.color; |
| 36 | font_size: 20px ; |
| 37 | min-width: 1500px; |
| 38 | } |
| 39 | } |
| 40 | TouchArea { clicked => { value = data.text; } } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | ```cpp |
| 47 | auto handle = TestCase::create(); |
| 48 | const TestCase &instance = *handle; |
| 49 | slint_testing::send_mouse_click(&instance, 5., 205.); |
| 50 | assert_eq(instance.get_value(), "Green"); |
| 51 | assert(instance.get_test()); |
| 52 | assert_eq(instance.get_listview_viewport_height(), 8. * 100.); |
| 53 | assert_eq(instance.get_listview_viewport_width(), 1500.); |
| 54 | |
| 55 | // scroll all the way down with the mouse wheel and click on the last item |
| 56 | for (int i = 0; i < 10; ++i) { |
| 57 | instance.window().dispatch_pointer_scroll_event(slint::LogicalPosition({25.0, 105.0}), 0, -50); |
| 58 | } |
| 59 | slint_testing::send_mouse_click(&instance, 5., 441.); |
| 60 | assert_eq(instance.get_value(), "Cyan"); |
| 61 | ``` |
| 62 | |
| 63 | ```rust |
| 64 | let instance = TestCase::new().unwrap(); |
| 65 | slint_testing::send_mouse_click(&instance, 5., 205.); |
| 66 | assert_eq!(instance.get_value(), "Green"); |
| 67 | assert!(instance.get_test()); |
| 68 | assert_eq!(instance.get_listview_viewport_height(), 8. * 100.); |
| 69 | assert_eq!(instance.get_listview_viewport_width(), 1500.); |
| 70 | |
| 71 | // scroll all the way down with the mouse wheel and click on the last item |
| 72 | use slint::{LogicalPosition, platform::WindowEvent }; |
| 73 | for _ in 0..10 { |
| 74 | instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 105.0), delta_x: 0.0, delta_y: -50.0 }); |
| 75 | } |
| 76 | slint_testing::send_mouse_click(&instance, 5., 441.); |
| 77 | assert_eq!(instance.get_value(), "Cyan"); |
| 78 | |
| 79 | ``` |
| 80 | |
| 81 | ```js |
| 82 | var instance = new slint.TestCase(); |
| 83 | slintlib.private_api.send_mouse_click(instance, 5., 205.); |
| 84 | assert.equal(instance.value, "Green"); |
| 85 | assert(instance.test); |
| 86 | assert.equal(instance.listview_viewport_height, 8. * 100.); |
| 87 | assert.equal(instance.listview_viewport_width, 1500.); |
| 88 | ``` |
| 89 | |
| 90 | */ |
| 91 | |