Skip to content

Commit

Permalink
Implement PageUp\PageDown navigation to make it work with Compositing…
Browse files Browse the repository at this point in the history
… renderer
  • Loading branch information
Takoooooo committed Nov 30, 2022
1 parent babd474 commit 688fc5a
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Input.Platform;
Expand Down Expand Up @@ -189,19 +190,29 @@ private void Search(TreeDataGrid treeDataGrid, string candidatePattern, int sele
void ITreeDataGridSelectionInteraction.OnPreviewKeyDown(TreeDataGrid sender, KeyEventArgs e)
{

static bool IsElementFullyVisibleToUser(TransformedBounds controlBounds)
static bool IsRowFullyVisibleToUser(TreeDataGridRow row)
{
var rect = controlBounds.Bounds.TransformToAABB(controlBounds.Transform);
// Round rect.Bottom because sometimes it's value isn't precise.
return controlBounds.Clip.Contains(rect.TopLeft) &&
controlBounds.Clip.Contains(new Point(rect.BottomRight.X, Math.Round(rect.BottomRight.Y, 5, MidpointRounding.ToZero)));
var scrollContentPresenter = row.FindAncestorOfType<ScrollContentPresenter>();
if (scrollContentPresenter != null)
{
var transform = row.TransformToVisual(scrollContentPresenter);
if (transform != null)
{
var transformedBounds = new Rect(row.Bounds.Size).TransformToAABB((Matrix)transform);
if (scrollContentPresenter.Bounds.Contains(transformedBounds.TopLeft) && scrollContentPresenter.Bounds.Contains(transformedBounds.BottomRight))
{
return true;
}
}
}
return false;

}

static bool GetRowIndexIfFullyVisible(IControl? control, out int index)
{
if (control is TreeDataGridRow row &&
row.TransformedBounds != null &&
IsElementFullyVisibleToUser(row.TransformedBounds.Value))
IsRowFullyVisibleToUser(row))
{
index = row.RowIndex;
return true;
Expand Down Expand Up @@ -240,8 +251,7 @@ void UpdateSelectionAndBringIntoView(int newIndex)
if (isIndexSet &&
SelectedIndex[0] != newIndex &&
sender.TryGetRow(SelectedIndex[0]) is TreeDataGridRow row &&
row.TransformedBounds != null &&
IsElementFullyVisibleToUser(row.TransformedBounds.Value))
IsRowFullyVisibleToUser(row))
{
UpdateSelectionAndBringIntoView(newIndex);
return;
Expand All @@ -266,11 +276,10 @@ void UpdateSelectionAndBringIntoView(int newIndex)
break;
}
}
if (isIndexSet &&
SelectedIndex[0] != newIndex &&
if (isIndexSet &&
SelectedIndex[0] != newIndex &&
sender.TryGetRow(SelectedIndex[0]) is TreeDataGridRow row &&
row.TransformedBounds != null &&
IsElementFullyVisibleToUser(row.TransformedBounds.Value))
IsRowFullyVisibleToUser(row))
{
UpdateSelectionAndBringIntoView(newIndex);
return;
Expand Down Expand Up @@ -333,7 +342,7 @@ e.Source is IControl source &&

void ITreeDataGridSelectionInteraction.OnPointerReleased(TreeDataGrid sender, PointerReleasedEventArgs e)
{
if (!e.Handled &&
if (!e.Handled &&
_pressedPoint != s_InvalidPoint &&
e.Source is IControl source &&
sender.TryGetRow(source, out var row))
Expand Down

0 comments on commit 688fc5a

Please sign in to comment.