Browse Source

process scroll events in ScrollContentPresenter in more generic way (support also horizontal scroll)
and horizontal scroll support in VirtualizationMode

donandren 9 years ago
parent
commit
b9ad9b82ce

+ 1 - 1
src/Avalonia.Controls/Presenters/ItemsPresenter.cs

@@ -69,7 +69,7 @@ namespace Avalonia.Controls.Presenters
         Action ILogicalScrollable.InvalidateScroll { get; set; }
 
         /// <inheritdoc/>
-        Size ILogicalScrollable.ScrollSize => new Size(0, 1);
+        Size ILogicalScrollable.ScrollSize => new Size(1, 1);
 
         /// <inheritdoc/>
         Size ILogicalScrollable.PageScrollSize => new Size(0, 1);

+ 19 - 13
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@@ -231,26 +231,32 @@ namespace Avalonia.Controls.Presenters
         /// <inheritdoc/>
         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
             }
         }
     }
-}
+}