From 4f68669c2d32232786acb289875f7cc36dee9b19 Mon Sep 17 00:00:00 2001 From: xiaoy312 Date: Wed, 23 Oct 2024 16:42:02 -0400 Subject: [PATCH] chore: fix build --- .../ZoomContentControl/ZoomContentControl.cs | 14 ++++++++------ src/Uno.Toolkit.UI/Extensions/TwoDExtensions.cs | 14 +++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs b/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs index f2a77770e..064627e0b 100644 --- a/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs +++ b/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs @@ -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)); } } @@ -315,7 +315,9 @@ 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); @@ -323,8 +325,8 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) 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 @@ -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; diff --git a/src/Uno.Toolkit.UI/Extensions/TwoDExtensions.cs b/src/Uno.Toolkit.UI/Extensions/TwoDExtensions.cs index 4033cf7f8..855975380 100644 --- a/src/Uno.Toolkit.UI/Extensions/TwoDExtensions.cs +++ b/src/Uno.Toolkit.UI/Extensions/TwoDExtensions.cs @@ -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; @@ -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); @@ -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); }