Fix ListView implementation in C++

Regressed in commit 4da79ac69a
This commit is contained in:
Olivier Goffart 2025-01-22 12:32:13 +01:00
parent d3cec1f269
commit 3d664578dd
2 changed files with 17 additions and 1 deletions

View file

@ -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

View file

@ -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