diff --git a/api/cpp/include/slint.h b/api/cpp/include/slint.h index c542c1c66..acbdfb5b0 100644 --- a/api/cpp/include/slint.h +++ b/api/cpp/include/slint.h @@ -1244,7 +1244,7 @@ public: vp_width = std::max(vp_width, (*x.ptr)->listview_layout(&offset)); } viewport_width->set(vp_width); - return offset; + return offset - viewport_y; } void model_set_row_data(size_t row, const ModelData &data) const diff --git a/tests/cases/elements/listview.slint b/tests/cases/elements/listview.slint index 07733191e..1d84dd1ec 100644 --- a/tests/cases/elements/listview.slint +++ b/tests/cases/elements/listview.slint @@ -51,6 +51,13 @@ assert_eq(instance.get_value(), "Green"); assert(instance.get_test()); assert_eq(instance.get_listview_viewport_height(), 8. * 100.); assert_eq(instance.get_listview_viewport_width(), 1500.); + +// scroll all the way down with the mouse wheel and click on the last item +for (int i = 0; i < 10; ++i) { + instance.window().dispatch_pointer_scroll_event(slint::LogicalPosition({25.0, 105.0}), 0, -50); +} +slint_testing::send_mouse_click(&instance, 5., 441.); +assert_eq(instance.get_value(), "Cyan"); ``` ```rust @@ -60,6 +67,15 @@ assert_eq!(instance.get_value(), "Green"); assert!(instance.get_test()); assert_eq!(instance.get_listview_viewport_height(), 8. * 100.); assert_eq!(instance.get_listview_viewport_width(), 1500.); + +// scroll all the way down with the mouse wheel and click on the last item +use slint::{LogicalPosition, platform::WindowEvent }; +for _ in 0..10 { + instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 105.0), delta_x: 0.0, delta_y: -50.0 }); +} +slint_testing::send_mouse_click(&instance, 5., 441.); +assert_eq!(instance.get_value(), "Cyan"); + ``` ```js