From aa63c8377bd987b1c8511f15a55e17dcf8da4323 Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Sun, 8 Dec 2024 21:57:10 +0800 Subject: [PATCH 1/2] Fix rtl scroll (#16667) --- .../Presenters/ScrollContentPresenter.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs index aa62eaaf065..f25080b4ff3 100644 --- a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs @@ -514,7 +514,7 @@ private void OnScrollGesture(object? sender, ScrollGestureEventArgs e) Vector delta = default; if (isLogical) _activeLogicalGestureScrolls?.TryGetValue(e.Id, out delta); - delta += e.Delta; + delta += CheckFlowDirection(e.Delta); if (isLogical && scrollable is object) { @@ -665,7 +665,7 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e) var x = Offset.X; var y = Offset.Y; - var delta = e.Delta; + var delta = CheckFlowDirection(e.Delta); // KeyModifiers.Shift should scroll in horizontal direction. This does not work on every platform. // If Shift-Key is pressed and X is close to 0 we swap the Vector. @@ -1065,5 +1065,14 @@ private static (double previous, double next) FindNearestSnapPoint(IReadOnlyList return snapPointsInfo; } + + private Vector CheckFlowDirection(Vector delta) + { + if (FlowDirection == Media.FlowDirection.RightToLeft) + { + return delta.WithX(-delta.X); + } + return delta; + } } } From 4bc1d1718f598bc062f5a877a1c77a87b74ba84c Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Thu, 16 Jan 2025 00:47:24 +0800 Subject: [PATCH 2/2] fix shift + scroll --- .../Presenters/ScrollContentPresenter.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs index f25080b4ff3..3d95fc0fdfa 100644 --- a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs @@ -201,7 +201,7 @@ public SnapPointsAlignment HorizontalSnapPointsAlignment /// public SnapPointsAlignment VerticalSnapPointsAlignment { - get => GetValue(VerticalSnapPointsAlignmentProperty); + get => GetValue(VerticalSnapPointsAlignmentProperty); set => SetValue(VerticalSnapPointsAlignmentProperty, value); } @@ -514,7 +514,7 @@ private void OnScrollGesture(object? sender, ScrollGestureEventArgs e) Vector delta = default; if (isLogical) _activeLogicalGestureScrolls?.TryGetValue(e.Id, out delta); - delta += CheckFlowDirection(e.Delta); + delta += AdjustDeltaForFlowDirection(e.Delta, FlowDirection); if (isLogical && scrollable is object) { @@ -665,7 +665,7 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e) var x = Offset.X; var y = Offset.Y; - var delta = CheckFlowDirection(e.Delta); + var delta = e.Delta; // KeyModifiers.Shift should scroll in horizontal direction. This does not work on every platform. // If Shift-Key is pressed and X is close to 0 we swap the Vector. @@ -673,7 +673,11 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e) { delta = new Vector(delta.Y, delta.X); } - + else + { + delta = AdjustDeltaForFlowDirection(delta, FlowDirection); + } + if (Extent.Height > Viewport.Height) { double height = isLogical ? scrollable!.ScrollSize.Height : 50; @@ -954,7 +958,7 @@ private Vector SnapOffset(Vector offset, Vector direction = default, bool snapTo midPoint = (previousSnapPoint + nextSnapPoint) / 2; } - var nearestSnapPoint = snapToNext ? (direction.Y > 0 ? previousSnapPoint : nextSnapPoint ) : + var nearestSnapPoint = snapToNext ? (direction.Y > 0 ? previousSnapPoint : nextSnapPoint) : estimatedOffset.Y < midPoint ? previousSnapPoint : nextSnapPoint; offset = new Vector(offset.X, nearestSnapPoint - diff.Y); @@ -977,7 +981,7 @@ private Vector SnapOffset(Vector offset, Vector direction = default, bool snapTo midPoint = (previousSnapPoint + nextSnapPoint) / 2; } - var nearestSnapPoint = snapToNext ? (direction.X > 0 ? previousSnapPoint : nextSnapPoint) : + var nearestSnapPoint = snapToNext ? (direction.X > 0 ? previousSnapPoint : nextSnapPoint) : estimatedOffset.X < midPoint ? previousSnapPoint : nextSnapPoint; offset = new Vector(nearestSnapPoint - diff.X, offset.Y); @@ -1046,9 +1050,9 @@ private static (double previous, double next) FindNearestSnapPoint(IReadOnlyList var snapPointsInfo = scrollable as IScrollSnapPointsInfo; - if(snapPointsInfo != _scrollSnapPointsInfo) + if (snapPointsInfo != _scrollSnapPointsInfo) { - if(_scrollSnapPointsInfo != null) + if (_scrollSnapPointsInfo != null) { _scrollSnapPointsInfo.VerticalSnapPointsChanged -= ScrollSnapPointsInfoSnapPointsChanged; _scrollSnapPointsInfo.HorizontalSnapPointsChanged -= ScrollSnapPointsInfoSnapPointsChanged; @@ -1056,7 +1060,7 @@ private static (double previous, double next) FindNearestSnapPoint(IReadOnlyList _scrollSnapPointsInfo = snapPointsInfo; - if(_scrollSnapPointsInfo != null) + if (_scrollSnapPointsInfo != null) { _scrollSnapPointsInfo.VerticalSnapPointsChanged += ScrollSnapPointsInfoSnapPointsChanged; _scrollSnapPointsInfo.HorizontalSnapPointsChanged += ScrollSnapPointsInfoSnapPointsChanged; @@ -1066,9 +1070,9 @@ private static (double previous, double next) FindNearestSnapPoint(IReadOnlyList return snapPointsInfo; } - private Vector CheckFlowDirection(Vector delta) + private static Vector AdjustDeltaForFlowDirection(Vector delta, Media.FlowDirection flowDirection) { - if (FlowDirection == Media.FlowDirection.RightToLeft) + if (flowDirection == Media.FlowDirection.RightToLeft) { return delta.WithX(-delta.X); }