Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions internal/backends/qt/qt_widgets/scrollview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct NativeScrollView {
pub has_focus: Property<bool>,
pub vertical_scrollbar_policy: Property<ScrollBarPolicy>,
pub horizontal_scrollbar_policy: Property<ScrollBarPolicy>,
pub scrolled: Callback<VoidArg>,
data: Property<NativeSliderData>,
widget_ptr: std::cell::Cell<SlintTypeErasedWidgetPtr>,
animation_tracker: Property<i32>,
Expand Down Expand Up @@ -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 { .. } => {
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ export component NativeScrollView {
in property <ScrollBarPolicy> vertical-scrollbar-policy;
in property <ScrollBarPolicy> horizontal-scrollbar-policy;
in property <bool> enabled: true;
callback scrolled;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
Expand Down
2 changes: 2 additions & 0 deletions internal/compiler/widgets/qt/internal-scrollview.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading