Browse Source

Renamed IScrollable -> ILogicalScrollable

We're going to need IScrollable as an interface to ScrollViewer-type
controls.
pull/554/head
Steven Kirk 10 years ago
parent
commit
b44589e0cb
  1. 4
      Avalonia.sln
  2. 8
      samples/XamlTestApplicationPcl/TestScrollable.cs
  3. 2
      src/Avalonia.Controls/Avalonia.Controls.csproj
  4. 2
      src/Avalonia.Controls/Presenters/ItemVirtualizer.cs
  5. 4
      src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs
  6. 22
      src/Avalonia.Controls/Presenters/ItemsPresenter.cs
  7. 8
      src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs
  8. 4
      src/Avalonia.Controls/Primitives/ILogicalScrollable.cs
  9. 22
      tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization.cs
  10. 2
      tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests_IScrollable.cs

4
Avalonia.sln

@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 14
VisualStudioVersion = 14.0.24720.0 VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Base", "src\Avalonia.Base\Avalonia.Base.csproj", "{B09B78D8-9B26-48B0-9149-D64A2F120F3F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Base", "src\Avalonia.Base\Avalonia.Base.csproj", "{B09B78D8-9B26-48B0-9149-D64A2F120F3F}"
EndProject EndProject
@ -172,6 +172,8 @@ Global
src\Shared\RenderHelpers\RenderHelpers.projitems*{47be08a7-5985-410b-9ffc-2264b8ea595f}*SharedItemsImports = 4 src\Shared\RenderHelpers\RenderHelpers.projitems*{47be08a7-5985-410b-9ffc-2264b8ea595f}*SharedItemsImports = 4
src\Skia\Avalonia.Skia\Avalonia.Skia.projitems*{47be08a7-5985-410b-9ffc-2264b8ea595f}*SharedItemsImports = 4 src\Skia\Avalonia.Skia\Avalonia.Skia.projitems*{47be08a7-5985-410b-9ffc-2264b8ea595f}*SharedItemsImports = 4
samples\TestApplicationShared\TestApplicationShared.projitems*{e3a1060b-50d0-44e8-88b6-f44ef2e5bd72}*SharedItemsImports = 4 samples\TestApplicationShared\TestApplicationShared.projitems*{e3a1060b-50d0-44e8-88b6-f44ef2e5bd72}*SharedItemsImports = 4
src\Shared\RenderHelpers\RenderHelpers.projitems*{bd43f7c0-396b-4aa1-bad9-dfde54d51298}*SharedItemsImports = 4
src\Skia\Avalonia.Skia\Avalonia.Skia.projitems*{bd43f7c0-396b-4aa1-bad9-dfde54d51298}*SharedItemsImports = 4
src\Shared\RenderHelpers\RenderHelpers.projitems*{3e908f67-5543-4879-a1dc-08eace79b3cd}*SharedItemsImports = 4 src\Shared\RenderHelpers\RenderHelpers.projitems*{3e908f67-5543-4879-a1dc-08eace79b3cd}*SharedItemsImports = 4
src\Shared\PlatformSupport\PlatformSupport.projitems*{e1aa3dbf-9056-4530-9376-18119a7a3ffe}*SharedItemsImports = 4 src\Shared\PlatformSupport\PlatformSupport.projitems*{e1aa3dbf-9056-4530-9376-18119a7a3ffe}*SharedItemsImports = 4
EndGlobalSection EndGlobalSection

8
samples/XamlTestApplicationPcl/TestScrollable.cs

@ -7,7 +7,7 @@ using Avalonia.VisualTree;
namespace XamlTestApplication namespace XamlTestApplication
{ {
public class TestScrollable : Control, IScrollable public class TestScrollable : Control, ILogicalScrollable
{ {
private int itemCount = 100; private int itemCount = 100;
private Size _extent; private Size _extent;
@ -18,12 +18,12 @@ namespace XamlTestApplication
public bool IsLogicalScrollEnabled => true; public bool IsLogicalScrollEnabled => true;
public Action InvalidateScroll { get; set; } public Action InvalidateScroll { get; set; }
Size IScrollable.Extent Size ILogicalScrollable.Extent
{ {
get { return _extent; } get { return _extent; }
} }
Vector IScrollable.Offset Vector ILogicalScrollable.Offset
{ {
get { return _offset; } get { return _offset; }
@ -34,7 +34,7 @@ namespace XamlTestApplication
} }
} }
Size IScrollable.Viewport Size ILogicalScrollable.Viewport
{ {
get { return _viewport; } get { return _viewport; }
} }

2
src/Avalonia.Controls/Avalonia.Controls.csproj

@ -74,7 +74,7 @@
<Compile Include="Presenters\ItemVirtualizerSimple.cs" /> <Compile Include="Presenters\ItemVirtualizerSimple.cs" />
<Compile Include="Presenters\ItemVirtualizer.cs" /> <Compile Include="Presenters\ItemVirtualizer.cs" />
<Compile Include="Primitives\HeaderedSelectingControl.cs" /> <Compile Include="Primitives\HeaderedSelectingControl.cs" />
<Compile Include="Primitives\IScrollable.cs" /> <Compile Include="Primitives\ILogicalScrollable.cs" />
<Compile Include="Primitives\TabStripItem.cs" /> <Compile Include="Primitives\TabStripItem.cs" />
<Compile Include="Primitives\TemplateAppliedEventArgs.cs" /> <Compile Include="Primitives\TemplateAppliedEventArgs.cs" />
<Compile Include="SelectionChangedEventArgs.cs" /> <Compile Include="SelectionChangedEventArgs.cs" />

2
src/Avalonia.Controls/Presenters/ItemVirtualizer.cs

@ -30,7 +30,7 @@ namespace Avalonia.Controls.Presenters
public static ItemVirtualizer Create(ItemsPresenter owner) public static ItemVirtualizer Create(ItemsPresenter owner)
{ {
var virtualizingPanel = owner.Panel as IVirtualizingPanel; var virtualizingPanel = owner.Panel as IVirtualizingPanel;
var scrollable = (IScrollable)owner; var scrollable = (ILogicalScrollable)owner;
if (virtualizingPanel != null && scrollable.InvalidateScroll != null) if (virtualizingPanel != null && scrollable.InvalidateScroll != null)
{ {

4
src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs

@ -83,13 +83,13 @@ namespace Avalonia.Controls.Presenters
public override void Arranging(Size finalSize) public override void Arranging(Size finalSize)
{ {
CreateRemoveContainers(); CreateRemoveContainers();
((IScrollable)Owner).InvalidateScroll(); ((ILogicalScrollable)Owner).InvalidateScroll();
} }
public override void ItemsChanged(IEnumerable items, NotifyCollectionChangedEventArgs e) public override void ItemsChanged(IEnumerable items, NotifyCollectionChangedEventArgs e)
{ {
base.ItemsChanged(items, e); base.ItemsChanged(items, e);
((IScrollable)Owner).InvalidateScroll(); ((ILogicalScrollable)Owner).InvalidateScroll();
} }
private void CreateRemoveContainers() private void CreateRemoveContainers()

22
src/Avalonia.Controls/Presenters/ItemsPresenter.cs

@ -13,7 +13,7 @@ namespace Avalonia.Controls.Presenters
/// <summary> /// <summary>
/// Displays items inside an <see cref="ItemsControl"/>. /// Displays items inside an <see cref="ItemsControl"/>.
/// </summary> /// </summary>
public class ItemsPresenter : ItemsPresenterBase, IScrollable public class ItemsPresenter : ItemsPresenterBase, ILogicalScrollable
{ {
/// <summary> /// <summary>
/// Defines the <see cref="VirtualizationMode"/> property. /// Defines the <see cref="VirtualizationMode"/> property.
@ -45,35 +45,35 @@ namespace Avalonia.Controls.Presenters
} }
/// <inheritdoc/> /// <inheritdoc/>
bool IScrollable.IsLogicalScrollEnabled bool ILogicalScrollable.IsLogicalScrollEnabled
{ {
get { return _virtualizer?.IsLogicalScrollEnabled ?? false; } get { return _virtualizer?.IsLogicalScrollEnabled ?? false; }
} }
/// <inheritdoc/> /// <inheritdoc/>
Action IScrollable.InvalidateScroll { get; set; } Action ILogicalScrollable.InvalidateScroll { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
Size IScrollable.Extent => _virtualizer.Extent; Size ILogicalScrollable.Extent => _virtualizer.Extent;
/// <inheritdoc/> /// <inheritdoc/>
Vector IScrollable.Offset Vector ILogicalScrollable.Offset
{ {
get { return _virtualizer.Offset; } get { return _virtualizer.Offset; }
set { _virtualizer.Offset = CoerceOffset(value); } set { _virtualizer.Offset = CoerceOffset(value); }
} }
/// <inheritdoc/> /// <inheritdoc/>
Size IScrollable.Viewport => _virtualizer.Viewport; Size ILogicalScrollable.Viewport => _virtualizer.Viewport;
/// <inheritdoc/> /// <inheritdoc/>
Size IScrollable.ScrollSize => new Size(0, 1); Size ILogicalScrollable.ScrollSize => new Size(0, 1);
/// <inheritdoc/> /// <inheritdoc/>
Size IScrollable.PageScrollSize => new Size(0, 1); Size ILogicalScrollable.PageScrollSize => new Size(0, 1);
/// <inheritdoc/> /// <inheritdoc/>
bool IScrollable.BringIntoView(IVisual target, Rect targetRect) bool ILogicalScrollable.BringIntoView(IVisual target, Rect targetRect)
{ {
return _virtualizer?.BringIntoView(target, targetRect) ?? false; return _virtualizer?.BringIntoView(target, targetRect) ?? false;
} }
@ -90,7 +90,7 @@ namespace Avalonia.Controls.Presenters
protected override void PanelCreated(IPanel panel) protected override void PanelCreated(IPanel panel)
{ {
_virtualizer = ItemVirtualizer.Create(this); _virtualizer = ItemVirtualizer.Create(this);
((IScrollable)this).InvalidateScroll?.Invoke(); ((ILogicalScrollable)this).InvalidateScroll?.Invoke();
if (!Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty)) if (!Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty))
{ {
@ -111,7 +111,7 @@ namespace Avalonia.Controls.Presenters
private Vector CoerceOffset(Vector value) private Vector CoerceOffset(Vector value)
{ {
var scrollable = (IScrollable)this; var scrollable = (ILogicalScrollable)this;
var maxX = Math.Max(scrollable.Extent.Width - scrollable.Viewport.Width, 0); var maxX = Math.Max(scrollable.Extent.Width - scrollable.Viewport.Width, 0);
var maxY = Math.Max(scrollable.Extent.Height - scrollable.Viewport.Height, 0); var maxY = Math.Max(scrollable.Extent.Height - scrollable.Viewport.Height, 0);
return new Vector(Clamp(value.X, 0, maxX), Clamp(value.Y, 0, maxY)); return new Vector(Clamp(value.X, 0, maxX), Clamp(value.Y, 0, maxY));

8
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@ -117,7 +117,7 @@ namespace Avalonia.Controls.Presenters
return false; return false;
} }
var scrollable = Child as IScrollable; var scrollable = Child as ILogicalScrollable;
if (scrollable?.IsLogicalScrollEnabled == true) if (scrollable?.IsLogicalScrollEnabled == true)
{ {
@ -231,7 +231,7 @@ namespace Avalonia.Controls.Presenters
{ {
if (Extent.Height > Viewport.Height) if (Extent.Height > Viewport.Height)
{ {
var scrollable = Child as IScrollable; var scrollable = Child as ILogicalScrollable;
if (scrollable?.IsLogicalScrollEnabled == true) if (scrollable?.IsLogicalScrollEnabled == true)
{ {
@ -259,7 +259,7 @@ namespace Avalonia.Controls.Presenters
private void UpdateScrollableSubscription(IControl child) private void UpdateScrollableSubscription(IControl child)
{ {
var scrollable = child as IScrollable; var scrollable = child as ILogicalScrollable;
_scrollableSubscription?.Dispose(); _scrollableSubscription?.Dispose();
_scrollableSubscription = null; _scrollableSubscription = null;
@ -278,7 +278,7 @@ namespace Avalonia.Controls.Presenters
} }
} }
private void UpdateFromScrollable(IScrollable scrollable) private void UpdateFromScrollable(ILogicalScrollable scrollable)
{ {
var logicalScroll = _scrollableSubscription != null; var logicalScroll = _scrollableSubscription != null;

4
src/Avalonia.Controls/Primitives/IScrollable.cs → src/Avalonia.Controls/Primitives/ILogicalScrollable.cs

@ -17,7 +17,7 @@ namespace Avalonia.Controls.Primitives
/// whereas logical scrolling means that the scrolling is handled by the child control itself /// whereas logical scrolling means that the scrolling is handled by the child control itself
/// and it can choose to do handle the scroll information as it sees fit. /// and it can choose to do handle the scroll information as it sees fit.
/// </remarks> /// </remarks>
public interface IScrollable public interface ILogicalScrollable
{ {
/// <summary> /// <summary>
/// Gets a value indicating whether logical scrolling is enabled on the control. /// Gets a value indicating whether logical scrolling is enabled on the control.
@ -34,7 +34,7 @@ namespace Avalonia.Controls.Primitives
/// </para> /// </para>
/// <para> /// <para>
/// This property is set by the parent <see cref="ScrollViewer"/> when the /// This property is set by the parent <see cref="ScrollViewer"/> when the
/// <see cref="IScrollable"/> is placed inside it. /// <see cref="ILogicalScrollable"/> is placed inside it.
/// </para> /// </para>
/// </remarks> /// </remarks>
Action InvalidateScroll { get; set; } Action InvalidateScroll { get; set; }

22
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization.cs

@ -21,7 +21,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.ApplyTemplate(); target.ApplyTemplate();
Assert.False(((IScrollable)target).IsLogicalScrollEnabled); Assert.False(((ILogicalScrollable)target).IsLogicalScrollEnabled);
} }
[Fact] [Fact]
@ -31,7 +31,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.ApplyTemplate(); target.ApplyTemplate();
Assert.False(((IScrollable)target).IsLogicalScrollEnabled); Assert.False(((ILogicalScrollable)target).IsLogicalScrollEnabled);
} }
[Fact] [Fact]
@ -46,7 +46,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.ApplyTemplate(); target.ApplyTemplate();
Assert.False(((IScrollable)target).IsLogicalScrollEnabled); Assert.False(((ILogicalScrollable)target).IsLogicalScrollEnabled);
} }
[Fact] [Fact]
@ -56,7 +56,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.ApplyTemplate(); target.ApplyTemplate();
Assert.True(((IScrollable)target).IsLogicalScrollEnabled); Assert.True(((ILogicalScrollable)target).IsLogicalScrollEnabled);
} }
[Fact] [Fact]
@ -130,7 +130,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.ApplyTemplate(); target.ApplyTemplate();
Assert.Equal(new Size(0, 20), ((IScrollable)target).Extent); Assert.Equal(new Size(0, 20), ((ILogicalScrollable)target).Extent);
} }
[Fact] [Fact]
@ -140,7 +140,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.ApplyTemplate(); target.ApplyTemplate();
Assert.Equal(new Size(20, 0), ((IScrollable)target).Extent); Assert.Equal(new Size(20, 0), ((ILogicalScrollable)target).Extent);
} }
[Fact] [Fact]
@ -152,7 +152,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.Measure(new Size(100, 100)); target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100)); target.Arrange(new Rect(0, 0, 100, 100));
Assert.Equal(new Size(0, 10), ((IScrollable)target).Viewport); Assert.Equal(new Size(0, 10), ((ILogicalScrollable)target).Viewport);
} }
[Fact] [Fact]
@ -164,7 +164,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
target.Measure(new Size(100, 100)); target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100)); target.Arrange(new Rect(0, 0, 100, 100));
Assert.Equal(new Size(10, 0), ((IScrollable)target).Viewport); Assert.Equal(new Size(10, 0), ((ILogicalScrollable)target).Viewport);
} }
[Fact] [Fact]
@ -206,7 +206,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
.Take(5) .Take(5)
.Concat(containers.Take(5)).ToList(); .Concat(containers.Take(5)).ToList();
Assert.Equal(new Vector(0, 5), ((IScrollable)target).Offset); Assert.Equal(new Vector(0, 5), ((ILogicalScrollable)target).Offset);
Assert.Equal(scrolledContainers, target.Panel.Children); Assert.Equal(scrolledContainers, target.Panel.Children);
for (var i = 0; i < target.Panel.Children.Count; ++i) for (var i = 0; i < target.Panel.Children.Count; ++i)
@ -215,7 +215,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
} }
scroller.Offset = new Vector(0, 0); scroller.Offset = new Vector(0, 0);
Assert.Equal(new Vector(0, 0), ((IScrollable)target).Offset); Assert.Equal(new Vector(0, 0), ((ILogicalScrollable)target).Offset);
Assert.Equal(containers, target.Panel.Children); Assert.Equal(containers, target.Panel.Children);
var dcs = target.Panel.Children.Select(x => x.DataContext).ToList(); var dcs = target.Panel.Children.Select(x => x.DataContext).ToList();
@ -241,7 +241,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
scroller.Offset = new Vector(0, 20); scroller.Offset = new Vector(0, 20);
Assert.Equal(new Vector(0, 20), ((IScrollable)target).Offset); Assert.Equal(new Vector(0, 20), ((ILogicalScrollable)target).Offset);
Assert.Equal(containers, target.Panel.Children); Assert.Equal(containers, target.Panel.Children);
for (var i = 0; i < target.Panel.Children.Count; ++i) for (var i = 0; i < target.Panel.Children.Count; ++i)

2
tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests_IScrollable.cs

@ -237,7 +237,7 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Rect(0, 0, 100, 100), scrollable.Bounds); Assert.Equal(new Rect(0, 0, 100, 100), scrollable.Bounds);
} }
private class TestScrollable : Control, IScrollable private class TestScrollable : Control, ILogicalScrollable
{ {
private Size _extent; private Size _extent;
private Vector _offset; private Vector _offset;

Loading…
Cancel
Save