Browse Source

Passing null gives us the point relative to the root.

And update the documentation for `GetPosition` to explain what `null` does (as in `GetCurrentPoint`).
pull/11087/head
Steven Kirk 3 years ago
parent
commit
5262eec4cf
  1. 4
      src/Avalonia.Base/Input/PointerEventArgs.cs
  2. 6
      src/Avalonia.Controls/Primitives/Thumb.cs

4
src/Avalonia.Base/Input/PointerEventArgs.cs

@ -77,14 +77,14 @@ namespace Avalonia.Input
/// <summary>
/// Gets the pointer position relative to a control.
/// </summary>
/// <param name="relativeTo">The control.</param>
/// <param name="relativeTo">The visual whose coordinate system to use. Pass null for toplevel coordinate system</param>
/// <returns>The pointer position in the control's coordinates.</returns>
public Point GetPosition(Visual? relativeTo) => GetPosition(_rootVisualPosition, relativeTo);
/// <summary>
/// Returns the PointerPoint associated with the current event
/// </summary>
/// <param name="relativeTo">The visual which coordinate system to use. Pass null for toplevel coordinate system</param>
/// <param name="relativeTo">The visual whose coordinate system to use. Pass null for toplevel coordinate system</param>
/// <returns></returns>
public PointerPoint GetCurrentPoint(Visual? relativeTo)
=> new PointerPoint(Pointer, GetPosition(relativeTo), _properties);

6
src/Avalonia.Controls/Primitives/Thumb.cs

@ -85,7 +85,7 @@ namespace Avalonia.Controls.Primitives
{
if (_lastPoint.HasValue)
{
var point = e.GetPosition((Visual?)this.GetVisualRoot());
var point = e.GetPosition(null);
var ev = new VectorEventArgs
{
RoutedEvent = DragDeltaEvent,
@ -100,7 +100,7 @@ namespace Avalonia.Controls.Primitives
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
_lastPoint = e.GetPosition((Visual?)this.GetVisualRoot());
_lastPoint = e.GetPosition(null);
var ev = new VectorEventArgs
{
@ -123,7 +123,7 @@ namespace Avalonia.Controls.Primitives
var ev = new VectorEventArgs
{
RoutedEvent = DragCompletedEvent,
Vector = (Vector)e.GetPosition((Visual?)this.GetVisualRoot()),
Vector = (Vector)e.GetPosition(null),
};
RaiseEvent(ev);

Loading…
Cancel
Save