Skip to content

Commit 7d038eb

Browse files
redstrateogoffart
authored andcommitted
Qt: Emit scrolled callback when dragging scrollbar
This is supposed to be emitted whenever the user performs an intentional interaction, which works whenever you scroll the Slint Flickable with the scrollwheel. Dragging the scrollbar on the Qt style didn't do anything, since that was never hooked up to this callback. I only implemented this in the Qt style, because that's the only one that uses the NativeScrollView element. See #9574.
1 parent 23bd3ea commit 7d038eb

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

internal/backends/qt/qt_widgets/scrollview.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct NativeScrollView {
2525
pub has_focus: Property<bool>,
2626
pub vertical_scrollbar_policy: Property<ScrollBarPolicy>,
2727
pub horizontal_scrollbar_policy: Property<ScrollBarPolicy>,
28+
pub scrolled: Callback<VoidArg>,
2829
data: Property<NativeSliderData>,
2930
widget_ptr: std::cell::Cell<SlintTypeErasedWidgetPtr>,
3031
animation_tracker: Property<i32>,
@@ -198,7 +199,12 @@ impl Item for NativeScrollView {
198199
return -value;
199200
}
200201
});
201-
value_prop.set(LogicalLength::new(-(new_val.min(max).max(0) as f32)));
202+
let old_val = value_prop.get();
203+
let new_val = LogicalLength::new(-(new_val.min(max).max(0) as f32));
204+
value_prop.set(new_val);
205+
if new_val != old_val {
206+
Self::FIELD_OFFSETS.scrolled.apply_pin(self).call(&());
207+
}
202208
InputEventResult::EventIgnored
203209
}
204210
MouseEvent::Moved { .. } => {
@@ -207,21 +213,30 @@ impl Item for NativeScrollView {
207213
let new_val = data.pressed_val
208214
+ ((pos as f32) - data.pressed_x) * (max + (page_size as f32))
209215
/ size as f32;
210-
value_prop.set(LogicalLength::new(-new_val.min(max).max(0.)));
216+
let old_val = value_prop.get();
217+
let new_val = LogicalLength::new(-new_val.min(max).max(0.));
218+
value_prop.set(new_val);
219+
if new_val != old_val {
220+
Self::FIELD_OFFSETS.scrolled.apply_pin(self).call(&());
221+
}
211222
InputEventResult::GrabMouse
212223
} else {
213224
InputEventResult::EventAccepted
214225
}
215226
}
216227
MouseEvent::Wheel { delta_x, delta_y, .. } => {
228+
let max = max as f32;
229+
let new_val;
217230
if horizontal {
218-
let max = max as f32;
219-
let new_val = value as f32 + delta_x;
220-
value_prop.set(LogicalLength::new(new_val.min(0.).max(-max)));
231+
new_val = value as f32 + delta_x;
221232
} else {
222-
let max = max as f32;
223-
let new_val = value as f32 + delta_y;
224-
value_prop.set(LogicalLength::new(new_val.min(0.).max(-max)));
233+
new_val = value as f32 + delta_y;
234+
}
235+
let old_val = value_prop.get();
236+
let new_val = LogicalLength::new(new_val.min(0.).max(-max));
237+
value_prop.set(new_val);
238+
if new_val != old_val {
239+
Self::FIELD_OFFSETS.scrolled.apply_pin(self).call(&());
225240
}
226241
InputEventResult::EventAccepted
227242
}

internal/compiler/builtins.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ export component NativeScrollView {
658658
in property <ScrollBarPolicy> vertical-scrollbar-policy;
659659
in property <ScrollBarPolicy> horizontal-scrollbar-policy;
660660
in property <bool> enabled: true;
661+
callback scrolled;
661662
//-default_size_binding:expands_to_parent_geometry
662663
//-is_internal
663664
}

internal/compiler/widgets/qt/internal-scrollview.slint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export component InternalScrollView {
3939

4040
horizontal-max: fli.viewport-width > fli.width ? fli.viewport-width - fli.width : 0phx;
4141
horizontal-page-size: fli.width;
42+
43+
scrolled => root.scrolled();
4244
}
4345

4446
fli := Flickable {

0 commit comments

Comments
 (0)