Browse Source

Merge branch 'master' into compiled-bindings-everywhere

pull/9443/head
Max Katz 4 years ago
committed by GitHub
parent
commit
c5fa3b0a14
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Avalonia.Base/Input/MouseDevice.cs
  2. 2
      src/Avalonia.Base/Input/PointerWheelEventArgs.cs
  3. 19
      src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

8
src/Avalonia.Base/Input/MouseDevice.cs

@ -196,18 +196,12 @@ namespace Avalonia.Input
PointerPointProperties props, PointerPointProperties props,
Vector delta, KeyModifiers inputModifiers, IInputElement? hitTest) Vector delta, KeyModifiers inputModifiers, IInputElement? hitTest)
{ {
var rawDelta = delta;
device = device ?? throw new ArgumentNullException(nameof(device)); device = device ?? throw new ArgumentNullException(nameof(device));
root = root ?? throw new ArgumentNullException(nameof(root)); root = root ?? throw new ArgumentNullException(nameof(root));
var source = _pointer.Captured ?? hitTest; var source = _pointer.Captured ?? hitTest;
// 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.
if (inputModifiers == KeyModifiers.Shift && MathUtilities.IsZero(delta.X))
{
delta = new Vector(delta.Y, delta.X);
}
if (source is not null) if (source is not null)
{ {
var e = new PointerWheelEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta); var e = new PointerWheelEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta);

2
src/Avalonia.Base/Input/PointerWheelEventArgs.cs

@ -9,7 +9,7 @@ namespace Avalonia.Input
internal PointerWheelEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, internal PointerWheelEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual,
Point rootVisualPosition, ulong timestamp, Point rootVisualPosition, ulong timestamp,
PointerPointProperties properties, KeyModifiers modifiers, Vector delta) PointerPointProperties properties, KeyModifiers modifiers, Vector delta)
: base(InputElement.PointerWheelChangedEvent, source, pointer, rootVisual, rootVisualPosition, : base(InputElement.PointerWheelChangedEvent, source, pointer, rootVisual, rootVisualPosition,
timestamp, properties, modifiers) timestamp, properties, modifiers)
{ {

19
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@ -5,6 +5,7 @@ using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Utilities;
using Avalonia.VisualTree; using Avalonia.VisualTree;
namespace Avalonia.Controls.Presenters namespace Avalonia.Controls.Presenters
@ -440,15 +441,23 @@ namespace Avalonia.Controls.Presenters
if (Extent.Height > Viewport.Height || Extent.Width > Viewport.Width) if (Extent.Height > Viewport.Height || Extent.Width > Viewport.Width)
{ {
var scrollable = Child as ILogicalScrollable; var scrollable = Child as ILogicalScrollable;
bool isLogical = scrollable?.IsLogicalScrollEnabled == true; var isLogical = scrollable?.IsLogicalScrollEnabled == true;
double x = Offset.X; var x = Offset.X;
double y = Offset.Y; var y = Offset.Y;
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.
if (e.KeyModifiers == KeyModifiers.Shift && MathUtilities.IsZero(delta.X))
{
delta = new Vector(delta.Y, delta.X);
}
if (Extent.Height > Viewport.Height) if (Extent.Height > Viewport.Height)
{ {
double height = isLogical ? scrollable!.ScrollSize.Height : 50; double height = isLogical ? scrollable!.ScrollSize.Height : 50;
y += -e.Delta.Y * height; y += -delta.Y * height;
y = Math.Max(y, 0); y = Math.Max(y, 0);
y = Math.Min(y, Extent.Height - Viewport.Height); y = Math.Min(y, Extent.Height - Viewport.Height);
} }
@ -456,7 +465,7 @@ namespace Avalonia.Controls.Presenters
if (Extent.Width > Viewport.Width) if (Extent.Width > Viewport.Width)
{ {
double width = isLogical ? scrollable!.ScrollSize.Width : 50; double width = isLogical ? scrollable!.ScrollSize.Width : 50;
x += -e.Delta.X * width; x += -delta.X * width;
x = Math.Max(x, 0); x = Math.Max(x, 0);
x = Math.Min(x, Extent.Width - Viewport.Width); x = Math.Min(x, Extent.Width - Viewport.Width);
} }

Loading…
Cancel
Save