@ -12,6 +12,7 @@ using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives ;
using Avalonia.Controls.Templates ;
using Avalonia.Input ;
using Avalonia.Layout ;
using Avalonia.Platform ;
using Avalonia.Rendering ;
using Avalonia.UnitTests ;
@ -722,10 +723,10 @@ namespace Avalonia.Controls.UnitTests.Presenters
public void GetControlInDirection_Down_Should_Return_Existing_Container_If_Materialized ( )
{
var target = CreateTarget ( ) ;
var scroller = ( TestScroller ) target . Parent ;
target . ApplyTemplate ( ) ;
target . Measure ( new Size ( 1 0 0 , 1 0 0 ) ) ;
target . Arrange ( new Rect ( 0 , 0 , 1 0 0 , 1 0 0 ) ) ;
scroller . Width = scroller . Height = 1 0 0 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
var from = target . Panel . Children [ 5 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
@ -739,10 +740,10 @@ namespace Avalonia.Controls.UnitTests.Presenters
public void GetControlInDirection_Down_Should_Scroll_If_Necessary ( )
{
var target = CreateTarget ( ) ;
var scroller = ( TestScroller ) target . Parent ;
target . ApplyTemplate ( ) ;
target . Measure ( new Size ( 1 0 0 , 1 0 0 ) ) ;
target . Arrange ( new Rect ( 0 , 0 , 1 0 0 , 1 0 0 ) ) ;
scroller . Width = scroller . Height = 1 0 0 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
var from = target . Panel . Children [ 9 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
@ -756,44 +757,40 @@ namespace Avalonia.Controls.UnitTests.Presenters
[Fact]
public void GetControlInDirection_Down_Should_Scroll_If_Partially_Visible ( )
{
using ( UnitTestApplication . Start ( new TestServices ( ) ) )
{
var target = CreateTarget ( ) ;
var scroller = ( ScrollContentPresenter ) target . Parent ;
var target = CreateTarget ( ) ;
var scroller = ( TestScroller ) target . Parent ;
scroller . Measure ( new Size ( 1 0 0 , 9 5 ) ) ;
scroller . Arrange ( new Rect ( 0 , 0 , 1 0 0 , 9 5 ) ) ;
scroller . Width = 1 0 0 ;
scroller . Height = 9 5 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
var from = target . Panel . Children [ 8 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
NavigationDirection . Down ,
from ) ;
var from = target . Panel . Children [ 8 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
NavigationDirection . Down ,
from ) ;
Assert . Equal ( new Vector ( 0 , 1 ) , ( ( ILogicalScrollable ) target ) . Offset ) ;
Assert . Same ( target . Panel . Children [ 8 ] , result ) ;
}
Assert . Equal ( new Vector ( 0 , 1 ) , ( ( ILogicalScrollable ) target ) . Offset ) ;
Assert . Same ( target . Panel . Children [ 8 ] , result ) ;
}
[Fact]
public void GetControlInDirection_Up_Should_Scroll_If_Partially_Visible_Item_Is_Currently_Shown ( )
{
using ( UnitTestApplication . Start ( new TestServices ( ) ) )
{
var target = CreateTarget ( ) ;
var scroller = ( ScrollContentPresenter ) target . Parent ;
var target = CreateTarget ( ) ;
var scroller = ( TestScroller ) target . Parent ;
scroller . Measure ( new Size ( 1 0 0 , 9 5 ) ) ;
scroller . Arrange ( new Rect ( 0 , 0 , 1 0 0 , 9 5 ) ) ;
( ( ILogicalScrollable ) target ) . Offset = new Vector ( 0 , 1 1 ) ;
scroller . Width = 1 0 0 ;
scroller . Height = 9 5 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
( ( ILogicalScrollable ) target ) . Offset = new Vector ( 0 , 1 1 ) ;
var from = target . Panel . Children [ 1 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
NavigationDirection . Up ,
from ) ;
var from = target . Panel . Children [ 1 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
NavigationDirection . Up ,
from ) ;
Assert . Equal ( new Vector ( 0 , 1 0 ) , ( ( ILogicalScrollable ) target ) . Offset ) ;
Assert . Same ( target . Panel . Children [ 0 ] , result ) ;
}
Assert . Equal ( new Vector ( 0 , 1 0 ) , ( ( ILogicalScrollable ) target ) . Offset ) ;
Assert . Same ( target . Panel . Children [ 0 ] , result ) ;
}
[Fact]
@ -834,10 +831,10 @@ namespace Avalonia.Controls.UnitTests.Presenters
public void GetControlInDirection_Right_Should_Return_Existing_Container_If_Materialized ( )
{
var target = CreateTarget ( orientation : Orientation . Horizontal ) ;
var scroller = ( TestScroller ) target . Parent ;
target . ApplyTemplate ( ) ;
target . Measure ( new Size ( 1 0 0 , 1 0 0 ) ) ;
target . Arrange ( new Rect ( 0 , 0 , 1 0 0 , 1 0 0 ) ) ;
scroller . Width = scroller . Height = 1 0 0 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
var from = target . Panel . Children [ 5 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
@ -851,10 +848,10 @@ namespace Avalonia.Controls.UnitTests.Presenters
public void GetControlInDirection_Right_Should_Scroll_If_Necessary ( )
{
var target = CreateTarget ( orientation : Orientation . Horizontal ) ;
var scroller = ( TestScroller ) target . Parent ;
target . ApplyTemplate ( ) ;
target . Measure ( new Size ( 1 0 0 , 1 0 0 ) ) ;
target . Arrange ( new Rect ( 0 , 0 , 1 0 0 , 1 0 0 ) ) ;
scroller . Width = scroller . Height = 1 0 0 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
var from = target . Panel . Children [ 9 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
@ -868,32 +865,31 @@ namespace Avalonia.Controls.UnitTests.Presenters
[Fact]
public void GetControlInDirection_Right_Should_Scroll_If_Partially_Visible ( )
{
using ( UnitTestApplication . Start ( new TestServices ( ) ) )
{
var target = CreateTarget ( orientation : Orientation . Horizontal ) ;
var scroller = ( ScrollContentPresenter ) target . Parent ;
var target = CreateTarget ( orientation : Orientation . Horizontal ) ;
var scroller = ( TestScroller ) target . Parent ;
scroller . Measure ( new Size ( 9 5 , 1 0 0 ) ) ;
scroller . Arrange ( new Rect ( 0 , 0 , 9 5 , 1 0 0 ) ) ;
scroller . Width = 9 5 ;
scroller . Height = 1 0 0 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
var from = target . Panel . Children [ 8 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
NavigationDirection . Right ,
from ) ;
var from = target . Panel . Children [ 8 ] ;
var result = ( ( ILogicalScrollable ) target ) . GetControlInDirection (
NavigationDirection . Right ,
from ) ;
Assert . Equal ( new Vector ( 1 , 0 ) , ( ( ILogicalScrollable ) target ) . Offset ) ;
Assert . Same ( target . Panel . Children [ 8 ] , result ) ;
}
Assert . Equal ( new Vector ( 1 , 0 ) , ( ( ILogicalScrollable ) target ) . Offset ) ;
Assert . Same ( target . Panel . Children [ 8 ] , result ) ;
}
[Fact]
public void GetControlInDirection_Left_Should_Scroll_If_Partially_Visible_Item_Is_Currently_Shown ( )
{
var target = CreateTarget ( orientation : Orientation . Horizontal ) ;
var scroller = ( TestScroller ) target . Parent ;
target . ApplyTemplate ( ) ;
target . Measure ( new Size ( 9 5 , 1 0 0 ) ) ;
target . Arrange ( new Rect ( 0 , 0 , 9 5 , 1 0 0 ) ) ;
scroller . Width = 9 5 ;
scroller . Height = 1 0 0 ;
scroller . LayoutManager . ExecuteInitialLayoutPass ( scroller ) ;
( ( ILogicalScrollable ) target ) . Offset = new Vector ( 1 1 , 0 ) ;
var from = target . Panel . Children [ 1 ] ;
@ -1007,8 +1003,6 @@ namespace Avalonia.Controls.UnitTests.Presenters
} ;
scroller . UpdateChild ( ) ;
new TestRoot ( ) . Child = scroller ;
return result ;
}
@ -1030,11 +1024,17 @@ namespace Avalonia.Controls.UnitTests.Presenters
} ) ;
}
private class TestScroller : ScrollContentPresenter , IRenderRoot
private class TestScroller : ScrollContentPresenter , IRenderRoot , ILayoutRoot
{
public IRenderer Renderer { get ; }
public Size ClientSize { get ; }
public Size MaxClientSize = > Size . Infinity ;
public double LayoutScaling = > 1 ;
public ILayoutManager LayoutManager { get ; } = new LayoutManager ( ) ;
public IRenderTarget CreateRenderTarget ( )
{
throw new NotImplementedException ( ) ;
@ -1054,6 +1054,11 @@ namespace Avalonia.Controls.UnitTests.Presenters
{
throw new NotImplementedException ( ) ;
}
protected override Size MeasureOverride ( Size availableSize )
{
return base . MeasureOverride ( availableSize ) ;
}
}
private class TestItemsPresenter : ItemsPresenter