From b9ad9b82ce72f1d4a68894414a9ceca06674df9e Mon Sep 17 00:00:00 2001 From: donandren Date: Sat, 18 Jun 2016 14:43:19 +0300 Subject: [PATCH] process scroll events in ScrollContentPresenter in more generic way (support also horizontal scroll) and horizontal scroll support in VirtualizationMode --- .../Presenters/ItemsPresenter.cs | 2 +- .../Presenters/ScrollContentPresenter.cs | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ItemsPresenter.cs b/src/Avalonia.Controls/Presenters/ItemsPresenter.cs index 4547c8fd45..ffc2680c83 100644 --- a/src/Avalonia.Controls/Presenters/ItemsPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ItemsPresenter.cs @@ -69,7 +69,7 @@ namespace Avalonia.Controls.Presenters Action ILogicalScrollable.InvalidateScroll { get; set; } /// - Size ILogicalScrollable.ScrollSize => new Size(0, 1); + Size ILogicalScrollable.ScrollSize => new Size(1, 1); /// Size ILogicalScrollable.PageScrollSize => new Size(0, 1); diff --git a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs index e0061ed386..d9f0260e39 100644 --- a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs @@ -231,26 +231,32 @@ namespace Avalonia.Controls.Presenters /// protected override void OnPointerWheelChanged(PointerWheelEventArgs e) { - if (Extent.Height > Viewport.Height) + if (Extent.Height > Viewport.Height || Extent.Width > Viewport.Width) { var scrollable = Child as ILogicalScrollable; + bool isLogical = scrollable?.IsLogicalScrollEnabled == true; - if (scrollable?.IsLogicalScrollEnabled == true) - { - var y = Offset.Y + (-e.Delta.Y * scrollable.ScrollSize.Height); + double x = Offset.X; + double y = Offset.Y; + + if (Extent.Height > Viewport.Height) + { + double height = isLogical ? scrollable.ScrollSize.Height : 50; + y += -e.Delta.Y * height; y = Math.Max(y, 0); y = Math.Min(y, Extent.Height - Viewport.Height); - Offset = new Vector(Offset.X, y); - e.Handled = true; } - else + + if (Extent.Width > Viewport.Width) { - var y = Offset.Y + (-e.Delta.Y * 50); - y = Math.Max(y, 0); - y = Math.Min(y, Extent.Height - Viewport.Height); - Offset = new Vector(Offset.X, y); - e.Handled = true; + double width = isLogical ? scrollable.ScrollSize.Width : 50; + x += -e.Delta.X * width; + x = Math.Max(x, 0); + x = Math.Min(x, Extent.Width - Viewport.Width); } + + Offset = new Vector(x, y); + e.Handled = true; } } @@ -308,4 +314,4 @@ namespace Avalonia.Controls.Presenters } } } -} +} \ No newline at end of file