Skip to content

Commit

Permalink
Merge pull request #6780 from ltetak/datagrid_drag_treshold
Browse files Browse the repository at this point in the history
DataGrid minimum distance threshold when dragging headers
  • Loading branch information
maxkatz6 authored and danwalmsley committed Oct 26, 2021
1 parent df77f18 commit 9da1793
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private enum DragMode

private const int DATAGRIDCOLUMNHEADER_resizeRegionWidth = 5;
private const double DATAGRIDCOLUMNHEADER_separatorThickness = 1;
private const int DATAGRIDCOLUMNHEADER_columnsDragTreshold = 5;

private bool _areHandlersSuspended;
private static DragMode _dragMode;
Expand Down Expand Up @@ -448,19 +449,6 @@ internal void OnMouseMove(PointerEventArgs args, Point mousePosition, Point mous

OnMouseMove_Reorder(ref handled, mousePosition, mousePositionHeaders, distanceFromLeft, distanceFromRight);

// if we still haven't done anything about moving the mouse while
// the button is down, we remember that we're dragging, but we don't
// claim to have actually handled the event
if (_dragMode == DragMode.MouseDown)
{
_dragMode = DragMode.Drag;
}

_lastMousePositionHeaders = mousePositionHeaders;

if (args.Pointer.Captured != this && _dragMode == DragMode.Drag)
args.Pointer.Capture(this);

SetDragCursor(mousePosition);
}

Expand Down Expand Up @@ -732,15 +720,19 @@ private void OnMouseMove_Reorder(ref bool handled, Point mousePosition, Point mo
{
return;
}

//handle entry into reorder mode
if (_dragMode == DragMode.MouseDown && _dragColumn == null && (distanceFromRight > DATAGRIDCOLUMNHEADER_resizeRegionWidth && distanceFromLeft > DATAGRIDCOLUMNHEADER_resizeRegionWidth))
if (_dragMode == DragMode.MouseDown && _dragColumn == null && _lastMousePositionHeaders != null && (distanceFromRight > DATAGRIDCOLUMNHEADER_resizeRegionWidth && distanceFromLeft > DATAGRIDCOLUMNHEADER_resizeRegionWidth))
{
handled = CanReorderColumn(OwningColumn);

if (handled)
var distanceFromInitial = (Vector)(mousePositionHeaders - _lastMousePositionHeaders);
if (distanceFromInitial.Length > DATAGRIDCOLUMNHEADER_columnsDragTreshold)
{
OnMouseMove_BeginReorder(mousePosition);
handled = CanReorderColumn(OwningColumn);

if (handled)
{
OnMouseMove_BeginReorder(mousePosition);
}
}
}

Expand Down

0 comments on commit 9da1793

Please sign in to comment.