Browse Source

Merge pull request #569 from donandren/horizontalscroll

Horizontal scroll support
Steven Kirk 9 years ago
parent
commit
9d7e18c669

+ 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
             }
         }
     }
-}
+}

+ 8 - 0
src/Windows/Avalonia.Win32/WindowImpl.cs

@@ -499,6 +499,14 @@ namespace Avalonia.Win32
                         ScreenToClient(DipFromLParam(lParam)),
                         new Vector(0, ((int)wParam >> 16) / wheelDelta), GetMouseModifiers(wParam));
                     break;
+                case UnmanagedMethods.WindowsMessage.WM_MOUSEHWHEEL:
+                    e = new RawMouseWheelEventArgs(
+                        WindowsMouseDevice.Instance,
+                        timestamp,
+                        _owner,
+                        ScreenToClient(DipFromLParam(lParam)),
+                        new Vector(-((int)wParam >> 16) / wheelDelta,0), GetMouseModifiers(wParam));
+                    break;
 
                 case UnmanagedMethods.WindowsMessage.WM_MOUSELEAVE:
                     _trackingMouse = false;