Skip to content

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Oct 23, 2024
1 parent beb4d12 commit 4f68669
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
if (_capturedPointerContext is { } context)
{
var position = e.GetCurrentPoint(this).Position;
var delta = context.Position - position;
var delta = context.Position.Subtract(position);
delta.X *= -1;

SetScrollValue(context.ScrollOffset + delta);
SetScrollValue(context.ScrollOffset.Add(delta));
}
}

Expand All @@ -315,16 +315,18 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
if (!IsZoomAllowed) return;

var oldPosition = (p.Position - vp.ActualSize.ToPoint().DivideBy(2)) - ScrollValue.MultiplyBy(1, -1);
var oldPosition = p.Position
.Subtract(vp.ActualSize.ToPoint().DivideBy(2))
.Subtract(ScrollValue.MultiplyBy(1, -1));
var basePosition = oldPosition.DivideBy(ZoomLevel);

var newZoom = ZoomLevel * (1 + p.Properties.MouseWheelDelta * ScaleWheelRatio);
//var newZoom = ZoomLevel + Math.Sign(p.Properties.MouseWheelDelta);
newZoom = Math.Clamp(newZoom, MinZoomLevel, MaxZoomLevel);

var newPosition = basePosition.MultiplyBy(newZoom);
var delta = (newPosition - oldPosition).MultiplyBy(-1, 1);
var offset = ScrollValue + delta;
var delta = (newPosition.Subtract(oldPosition)).MultiplyBy(-1, 1);
var offset = ScrollValue.Add(delta);

// note: updating ZoomLevel can have side effects on ScrollValue:
// ZoomLevel --UpdateScrollBars-> ScrollBar.Maximum --clamp-> ScrollBar.Value --bound-> H/VScrollValue
Expand All @@ -342,7 +344,7 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
var delta = e.KeyModifiers.HasFlag(Windows.System.VirtualKeyModifiers.Shift)
? new Point(magnitude, 0)
: new Point(0, -magnitude);
var offset = ScrollValue + delta;
var offset = ScrollValue.Add(delta);

SetScrollValue(offset);
e.Handled = true;
Expand Down
14 changes: 13 additions & 1 deletion src/Uno.Toolkit.UI/Extensions/TwoDExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
#if !HAS_UNO
#define MISSING_POINT_ARITHMETICS
#endif

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
Expand All @@ -14,6 +18,13 @@ internal static partial class TwoDExtensions // Point Mathematics
public static Point ToPoint(this Size x) => new Point(x.Width, x.Height);
public static Point ToPoint(this Vector2 x) => new Point(x.X, x.Y);

#if MISSING_POINT_ARITHMETICS
public static Point Add(this Point x, Point y) => new Point(x.X + y.X, x.Y + y.Y);
public static Point Subtract(this Point x, Point y) => new Point(x.X - y.X, x.Y - y.Y);
#else
public static Point Add(this Point x, Point y) => x + y;
public static Point Subtract(this Point x, Point y) => x - y;
#endif
public static Point MultiplyBy(this Point x, double scale) => new Point(x.X * scale, x.Y * scale);
public static Point MultiplyBy(this Point x, double scaleX, double scaleY) => new Point(x.X * scaleX, x.Y * scaleY);
public static Point DivideBy(this Point x, double scale) => new Point(x.X / scale, x.Y / scale);
Expand All @@ -25,5 +36,6 @@ internal static partial class TwoDExtensions // Size Mathematics
public static Size ToSize(this Vector2 x) => new Size(x.X, x.Y);

public static Size MultiplyBy(this Size x, double scale) => new Size(x.Width * scale, x.Height * scale);
public static Size MultiplyBy(this Size x, double scaleX, double scaleY) => new Size(x.Width * scaleX, x.Width * scaleY);
public static Size DivideBy(this Size x, double scale) => new Size(x.Width / scale, x.Height / scale);
}

0 comments on commit 4f68669

Please sign in to comment.