diff --git a/internal/backends/qt/qt_widgets/scrollview.rs b/internal/backends/qt/qt_widgets/scrollview.rs index 577043f20e7..14661379ff2 100644 --- a/internal/backends/qt/qt_widgets/scrollview.rs +++ b/internal/backends/qt/qt_widgets/scrollview.rs @@ -25,6 +25,7 @@ pub struct NativeScrollView { pub has_focus: Property, pub vertical_scrollbar_policy: Property, pub horizontal_scrollbar_policy: Property, + pub scrolled: Callback, data: Property, widget_ptr: std::cell::Cell, animation_tracker: Property, @@ -198,7 +199,12 @@ impl Item for NativeScrollView { return -value; } }); - value_prop.set(LogicalLength::new(-(new_val.min(max).max(0) as f32))); + let old_val = value_prop.get(); + let new_val = LogicalLength::new(-(new_val.min(max).max(0) as f32)); + value_prop.set(new_val); + if new_val != old_val { + Self::FIELD_OFFSETS.scrolled.apply_pin(self).call(&()); + } InputEventResult::EventIgnored } MouseEvent::Moved { .. } => { @@ -207,21 +213,30 @@ impl Item for NativeScrollView { let new_val = data.pressed_val + ((pos as f32) - data.pressed_x) * (max + (page_size as f32)) / size as f32; - value_prop.set(LogicalLength::new(-new_val.min(max).max(0.))); + let old_val = value_prop.get(); + let new_val = LogicalLength::new(-new_val.min(max).max(0.)); + value_prop.set(new_val); + if new_val != old_val { + Self::FIELD_OFFSETS.scrolled.apply_pin(self).call(&()); + } InputEventResult::GrabMouse } else { InputEventResult::EventAccepted } } MouseEvent::Wheel { delta_x, delta_y, .. } => { + let max = max as f32; + let new_val; if horizontal { - let max = max as f32; - let new_val = value as f32 + delta_x; - value_prop.set(LogicalLength::new(new_val.min(0.).max(-max))); + new_val = value as f32 + delta_x; } else { - let max = max as f32; - let new_val = value as f32 + delta_y; - value_prop.set(LogicalLength::new(new_val.min(0.).max(-max))); + new_val = value as f32 + delta_y; + } + let old_val = value_prop.get(); + let new_val = LogicalLength::new(new_val.min(0.).max(-max)); + value_prop.set(new_val); + if new_val != old_val { + Self::FIELD_OFFSETS.scrolled.apply_pin(self).call(&()); } InputEventResult::EventAccepted } diff --git a/internal/compiler/builtins.slint b/internal/compiler/builtins.slint index 1d58af7d3b9..d2708f131df 100644 --- a/internal/compiler/builtins.slint +++ b/internal/compiler/builtins.slint @@ -658,6 +658,7 @@ export component NativeScrollView { in property vertical-scrollbar-policy; in property horizontal-scrollbar-policy; in property enabled: true; + callback scrolled; //-default_size_binding:expands_to_parent_geometry //-is_internal } diff --git a/internal/compiler/widgets/qt/internal-scrollview.slint b/internal/compiler/widgets/qt/internal-scrollview.slint index 78a33f43b08..2c05e563540 100644 --- a/internal/compiler/widgets/qt/internal-scrollview.slint +++ b/internal/compiler/widgets/qt/internal-scrollview.slint @@ -39,6 +39,8 @@ export component InternalScrollView { horizontal-max: fli.viewport-width > fli.width ? fli.viewport-width - fli.width : 0phx; horizontal-page-size: fli.width; + + scrolled => root.scrolled(); } fli := Flickable {