Skip to content

Commit

Permalink
Merge pull request #99 from taublast/2-A
Browse files Browse the repository at this point in the history
Fix crash on Windows with latest VS
  • Loading branch information
taublast authored Oct 26, 2024
2 parents 052f172 + ee4f524 commit 62f34df
Show file tree
Hide file tree
Showing 66 changed files with 1,785 additions and 1,489 deletions.
140 changes: 68 additions & 72 deletions src/Engine/Controls/Carousel/SkiaCarousel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using DrawnUi.Maui.Draw;
using DrawnUi.Maui.Draw;
using DrawnUi.Maui.Draw;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Numerics;
using System.Numerics;
using SkiaControl = DrawnUi.Maui.Draw.SkiaControl;

namespace DrawnUi.Maui.Controls;
Expand Down Expand Up @@ -212,11 +207,12 @@ protected override int RenderViewsList(IEnumerable<SkiaControl> skiaControls, Sk
progress = CurrentPosition.X;
}

LastScrollProgress = ScrollProgress;
ScrollProgress = progress / progressMax;

if (ScrollProgress != LastScrollProgress)
{
LastScrollProgress = ScrollProgress;

TransitionDirection = ScrollProgress > LastScrollProgress ?
LinearDirectionType.Forward
: LinearDirectionType.Backward;
Expand Down Expand Up @@ -348,7 +344,7 @@ public double ScrollProgress
}
}

protected double LastScrollProgress { get; set; }
protected double LastScrollProgress { get; set; } = double.NegativeInfinity;

public double TransitionProgress
{
Expand Down Expand Up @@ -1278,95 +1274,95 @@ void ResetPan()

switch (args.Type)
{
case TouchActionResult.Down:
case TouchActionResult.Down:

// if (!IsUserFocused) //first finger down
if (args.Event.NumberOfTouches == 1) //first finger down
{
ResetPan();
}
// if (!IsUserFocused) //first finger down
if (args.Event.NumberOfTouches == 1) //first finger down
{
ResetPan();
}

consumed = this;
consumed = this;

break;
break;

case TouchActionResult.Panning when args.Event.NumberOfTouches == 1:
case TouchActionResult.Panning when args.Event.NumberOfTouches == 1:

if (!IsUserPanning)
{
//first pan
if (args.Event.Distance.Total.X == 0 || Math.Abs(args.Event.Distance.Total.Y) > Math.Abs(args.Event.Distance.Total.X) || Math.Abs(args.Event.Distance.Total.X) < 2)
{
return null;
}
}
if (!IsUserPanning)
{
//first pan
if (args.Event.Distance.Total.X == 0 || Math.Abs(args.Event.Distance.Total.Y) > Math.Abs(args.Event.Distance.Total.X) || Math.Abs(args.Event.Distance.Total.X) < 2)
{
return null;
}
}

if (!IsUserFocused)
{
ResetPan();
}
if (!IsUserFocused)
{
ResetPan();
}

//todo add direction
//this.IgnoreWrongDirection
//todo add direction
//this.IgnoreWrongDirection

IsUserPanning = true;
IsUserPanning = true;

var x = _panningOffset.X + args.Event.Distance.Delta.X / RenderingScale;
var y = _panningOffset.Y + args.Event.Distance.Delta.Y / RenderingScale;
var x = _panningOffset.X + args.Event.Distance.Delta.X / RenderingScale;
var y = _panningOffset.Y + args.Event.Distance.Delta.Y / RenderingScale;

Vector2 velocity;
float useVelocity = 0;
if (!IsVertical)
{
useVelocity = (float)(args.Event.Distance.Velocity.X / RenderingScale);
velocity = new(useVelocity, 0);
}
else
{
useVelocity = (float)(args.Event.Distance.Velocity.Y / RenderingScale);
velocity = new(0, useVelocity);
}
Vector2 velocity;
float useVelocity = 0;
if (!IsVertical)
{
useVelocity = (float)(args.Event.Distance.Velocity.X / RenderingScale);
velocity = new(useVelocity, 0);
}
else
{
useVelocity = (float)(args.Event.Distance.Velocity.Y / RenderingScale);
velocity = new(0, useVelocity);
}

//record velocity
VelocityAccumulator.CaptureVelocity(velocity);
//record velocity
VelocityAccumulator.CaptureVelocity(velocity);

//saving non clamped
_panningOffset.X = x;
_panningOffset.Y = y;
//saving non clamped
_panningOffset.X = x;
_panningOffset.Y = y;


var clamped = ClampOffset((float)x, (float)y, Bounces);
var clamped = ClampOffset((float)x, (float)y, Bounces);

//Debug.WriteLine($"[CAROUSEL] Panning: {_panningOffset:0} / {clamped:0}");
ApplyPosition(clamped);
//Debug.WriteLine($"[CAROUSEL] Panning: {_panningOffset:0} / {clamped:0}");
ApplyPosition(clamped);

consumed = this;
break;
consumed = this;
break;

case TouchActionResult.Up:
//Debug.WriteLine($"[Carousel] {args.Type} {IsUserFocused} {IsUserPanning} {InTransition}");
case TouchActionResult.Up:
//Debug.WriteLine($"[Carousel] {args.Type} {IsUserFocused} {IsUserPanning} {InTransition}");

if (IsUserFocused)
{
if (IsUserFocused)
{

if (IsUserPanning || InTransition)
{
consumed = this;
if (IsUserPanning || InTransition)
{
consumed = this;

var final = VelocityAccumulator.CalculateFinalVelocity(500);
var final = VelocityAccumulator.CalculateFinalVelocity(500);

//animate
CurrentSnap = CurrentPosition;
//animate
CurrentSnap = CurrentPosition;

ScrollToNearestAnchor(CurrentSnap, final);
}
ScrollToNearestAnchor(CurrentSnap, final);
}

IsUserPanning = false;
IsUserFocused = false;
IsUserPanning = false;
IsUserFocused = false;

}
}

break;
break;
}

if (consumed != null || IsUserPanning)
Expand Down
Loading

0 comments on commit 62f34df

Please sign in to comment.