Browse Source

Use single TappedEventArgs for all tapped events

pull/5340/head
Max Katz 6 years ago
parent
commit
f7a41c0793
  1. 10
      src/Avalonia.Input/Gestures.cs
  2. 4
      src/Avalonia.Input/InputElement.cs
  3. 18
      src/Avalonia.Input/TappedEventArgs.cs
  4. 44
      src/Avalonia.Input/TappedGestureEventArgs.cs

10
src/Avalonia.Input/Gestures.cs

@ -11,12 +11,12 @@ namespace Avalonia.Input
RoutingStrategies.Bubble,
typeof(Gestures));
public static readonly RoutedEvent<DoubleTappedEventArgs> DoubleTappedEvent = RoutedEvent.Register<DoubleTappedEventArgs>(
public static readonly RoutedEvent<TappedEventArgs> DoubleTappedEvent = RoutedEvent.Register<TappedEventArgs>(
"DoubleTapped",
RoutingStrategies.Bubble,
typeof(Gestures));
public static readonly RoutedEvent<RightTappedEventArgs> RightTappedEvent = RoutedEvent.Register<RightTappedEventArgs>(
public static readonly RoutedEvent<TappedEventArgs> RightTappedEvent = RoutedEvent.Register<TappedEventArgs>(
"RightTapped",
RoutingStrategies.Bubble,
typeof(Gestures));
@ -89,7 +89,7 @@ namespace Avalonia.Input
{
if (s_lastPress.TryGetTarget(out var target) && target == e.Source)
{
e.Source.RaiseEvent(new DoubleTappedEventArgs(e));
e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e));
}
}
}
@ -107,11 +107,11 @@ namespace Avalonia.Input
{
if (e.InitialPressMouseButton != MouseButton.Right)
{
e.Source.RaiseEvent(new RightTappedEventArgs(e));
e.Source.RaiseEvent(new TappedEventArgs(RightTappedEvent, e));
}
else
{
e.Source.RaiseEvent(new TappedEventArgs(e));
e.Source.RaiseEvent(new TappedEventArgs(TappedEvent, e));
}
}
}

4
src/Avalonia.Input/InputElement.cs

@ -181,7 +181,7 @@ namespace Avalonia.Input
/// <summary>
/// Defines the <see cref="DoubleTapped"/> event.
/// </summary>
public static readonly RoutedEvent<DoubleTappedEventArgs> DoubleTappedEvent = Gestures.DoubleTappedEvent;
public static readonly RoutedEvent<TappedEventArgs> DoubleTappedEvent = Gestures.DoubleTappedEvent;
private bool _isEffectivelyEnabled = true;
private bool _isFocused;
@ -355,7 +355,7 @@ namespace Avalonia.Input
/// <summary>
/// Occurs when a double-tap gesture occurs on the control.
/// </summary>
public event EventHandler<DoubleTappedEventArgs> DoubleTapped
public event EventHandler<TappedEventArgs> DoubleTapped
{
add { AddHandler(DoubleTappedEvent, value); }
remove { RemoveHandler(DoubleTappedEvent, value); }

18
src/Avalonia.Input/TappedEventArgs.cs

@ -0,0 +1,18 @@
using Avalonia.Interactivity;
using Avalonia.VisualTree;
namespace Avalonia.Input
{
public class TappedEventArgs : RoutedEventArgs
{
private readonly PointerEventArgs lastPointerEventArgs;
public TappedEventArgs(RoutedEvent routedEvent, PointerEventArgs lastPointerEventArgs)
: base(routedEvent)
{
this.lastPointerEventArgs = lastPointerEventArgs;
}
public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo);
}
}

44
src/Avalonia.Input/TappedGestureEventArgs.cs

@ -1,44 +0,0 @@
using Avalonia.Interactivity;
using Avalonia.VisualTree;
namespace Avalonia.Input
{
public class DoubleTappedEventArgs : RoutedEventArgs
{
private readonly PointerEventArgs lastPointerEventArgs;
public DoubleTappedEventArgs(PointerEventArgs lastPointerEventArgs)
: base(Gestures.DoubleTappedEvent)
{
this.lastPointerEventArgs = lastPointerEventArgs;
}
public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo);
}
public class TappedEventArgs : RoutedEventArgs
{
private readonly PointerEventArgs lastPointerEventArgs;
public TappedEventArgs(PointerEventArgs lastPointerEventArgs)
: base(Gestures.DoubleTappedEvent)
{
this.lastPointerEventArgs = lastPointerEventArgs;
}
public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo);
}
public class RightTappedEventArgs : RoutedEventArgs
{
private readonly PointerEventArgs lastPointerEventArgs;
public RightTappedEventArgs(PointerEventArgs lastPointerEventArgs)
: base(Gestures.DoubleTappedEvent)
{
this.lastPointerEventArgs = lastPointerEventArgs;
}
public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo);
}
}
Loading…
Cancel
Save