@ -6,14 +6,13 @@
using System ;
using System.Collections.Generic ;
using System.Collections.Specialized ;
using System.Text ;
using Avalonia.Controls.Utils ;
using Avalonia.Layout.Utils ;
namespace Avalonia.Controls.Repeaters
namespace Avalonia.Layout
{
internal class ElementManager
{
private readonly List < IControl > _ realizedElements = new List < IControl > ( ) ;
private readonly List < ILayoutable > _ realizedElements = new List < ILayoutable > ( ) ;
private readonly List < Rect > _ realizedElementLayoutBounds = new List < Rect > ( ) ;
private int _f irstRealizedDataIndex ;
private VirtualizingLayoutContext _ context ;
@ -34,7 +33,7 @@ namespace Avalonia.Controls.Repeaters
public void SetContext ( VirtualizingLayoutContext virtualContext ) = > _ context = virtualContext ;
public void OnBeginMeasure ( Orientation orientation )
public void OnBeginMeasure ( Scroll Orientation orientation )
{
if ( _ context ! = null )
{
@ -69,9 +68,9 @@ namespace Avalonia.Controls.Repeaters
return IsVirtualizingContext ? _ realizedElements . Count : _ context . ItemCount ;
}
public IControl GetAt ( int realizedIndex )
public ILayoutable GetAt ( int realizedIndex )
{
IControl element ;
ILayoutable element ;
if ( IsVirtualizingContext )
{
@ -100,7 +99,7 @@ namespace Avalonia.Controls.Repeaters
return element ;
}
public void Add ( IControl element , int dataIndex )
public void Add ( ILayoutable element , int dataIndex )
{
if ( _ realizedElements . Count = = 0 )
{
@ -111,7 +110,7 @@ namespace Avalonia.Controls.Repeaters
_ realizedElementLayoutBounds . Add ( default ) ;
}
public void Insert ( int realizedIndex , int dataIndex , IControl element )
public void Insert ( int realizedIndex , int dataIndex , ILayoutable element )
{
if ( realizedIndex = = 0 )
{
@ -208,7 +207,7 @@ namespace Avalonia.Controls.Repeaters
public bool IsIndexValidInData ( int currentIndex ) = > currentIndex > = 0 & & currentIndex < _ context . ItemCount ;
public IControl GetRealizedElement ( int dataIndex )
public ILayoutable GetRealizedElement ( int dataIndex )
{
return IsVirtualizingContext ?
GetAt ( GetRealizedRangeIndexFromDataIndex ( dataIndex ) ) :
@ -236,7 +235,7 @@ namespace Avalonia.Controls.Repeaters
}
}
public bool IsWindowConnected ( in Rect window , Orientation orientation , bool scrollOrientationSameAsFlow )
public bool IsWindowConnected ( in Rect window , Scroll Orientation orientation , bool scrollOrientationSameAsFlow )
{
bool intersects = false ;
@ -246,14 +245,14 @@ namespace Avalonia.Controls.Repeaters
var lastElementBounds = GetLayoutBoundsForRealizedIndex ( GetRealizedElementCount ( ) - 1 ) ;
var effectiveOrientation = scrollOrientationSameAsFlow ?
( orientation = = Orientation . Vertical ? Orientation . Horizontal : Orientation . Vertical ) :
( orientation = = Scroll Orientation. Vertical ? Scroll Orientation. Horizontal : Scroll Orientation. Vertical ) :
orientation ;
var windowStart = effectiveOrientation = = Orientation . Vertical ? window . Y : window . X ;
var windowEnd = effectiveOrientation = = Orientation . Vertical ? window . Y + window . Height : window . X + window . Width ;
var firstElementStart = effectiveOrientation = = Orientation . Vertical ? firstElementBounds . Y : firstElementBounds . X ;
var lastElementEnd = effectiveOrientation = = Orientation . Vertical ? lastElementBounds . Y + lastElementBounds . Height : lastElementBounds . X + lastElementBounds . Width ;
var windowStart = effectiveOrientation = = Scroll Orientation. Vertical ? window . Y : window . X ;
var windowEnd = effectiveOrientation = = Scroll Orientation. Vertical ? window . Y + window . Height : window . X + window . Width ;
var firstElementStart = effectiveOrientation = = Scroll Orientation. Vertical ? firstElementBounds . Y : firstElementBounds . X ;
var lastElementEnd = effectiveOrientation = = Scroll Orientation. Vertical ? lastElementBounds . Y + lastElementBounds . Height : lastElementBounds . X + lastElementBounds . Width ;
intersects =
firstElementStart < = windowEnd & &
@ -298,7 +297,7 @@ namespace Avalonia.Controls.Repeaters
}
}
public int GetElementDataIndex ( IControl suggestedAnchor )
public int GetElementDataIndex ( ILayoutable suggestedAnchor )
{
var it = _ realizedElements . IndexOf ( suggestedAnchor ) ;
return it ! = - 1 ? GetDataIndexFromRealizedRangeIndex ( it ) : - 1 ;
@ -314,7 +313,7 @@ namespace Avalonia.Controls.Repeaters
return IsVirtualizingContext ? dataIndex - _f irstRealizedDataIndex : dataIndex ;
}
private void DiscardElementsOutsideWindow ( in Rect window , Orientation orientation )
private void DiscardElementsOutsideWindow ( in Rect window , Scroll Orientation orientation )
{
// The following illustration explains the cutoff indices.
// We will clear all the realized elements from both ends
@ -369,12 +368,12 @@ namespace Avalonia.Controls.Repeaters
}
}
private static bool Intersects ( in Rect lhs , in Rect rhs , Orientation orientation )
private static bool Intersects ( in Rect lhs , in Rect rhs , Scroll Orientation orientation )
{
var lhsStart = orientation = = Orientation . Vertical ? lhs . Y : lhs . X ;
var lhsEnd = orientation = = Orientation . Vertical ? lhs . Y + lhs . Height : lhs . X + lhs . Width ;
var rhsStart = orientation = = Orientation . Vertical ? rhs . Y : rhs . X ;
var rhsEnd = orientation = = Orientation . Vertical ? rhs . Y + rhs . Height : rhs . X + rhs . Width ;
var lhsStart = orientation = = Scroll Orientation. Vertical ? lhs . Y : lhs . X ;
var lhsEnd = orientation = = Scroll Orientation. Vertical ? lhs . Y + lhs . Height : lhs . X + lhs . Width ;
var rhsStart = orientation = = Scroll Orientation. Vertical ? rhs . Y : rhs . X ;
var rhsEnd = orientation = = Scroll Orientation. Vertical ? rhs . Y + rhs . Height : rhs . X + rhs . Width ;
return lhsEnd > = rhsStart & & lhsStart < = rhsEnd ;
}