From f12435731b364a9d38f36f3e4e98a851bfb50d6a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 24 May 2016 10:57:02 +0200 Subject: [PATCH] Removed Thingamybob. --- .../Avalonia.Controls.csproj | 2 - .../Presenters/ThingamybobPresenter.cs | 114 ------------------ src/Avalonia.Controls/Thingamybob.cs | 25 ---- 3 files changed, 141 deletions(-) delete mode 100644 src/Avalonia.Controls/Presenters/ThingamybobPresenter.cs delete mode 100644 src/Avalonia.Controls/Thingamybob.cs diff --git a/src/Avalonia.Controls/Avalonia.Controls.csproj b/src/Avalonia.Controls/Avalonia.Controls.csproj index 9fe4fecc68..f3d7f10029 100644 --- a/src/Avalonia.Controls/Avalonia.Controls.csproj +++ b/src/Avalonia.Controls/Avalonia.Controls.csproj @@ -72,7 +72,6 @@ - @@ -167,7 +166,6 @@ - diff --git a/src/Avalonia.Controls/Presenters/ThingamybobPresenter.cs b/src/Avalonia.Controls/Presenters/ThingamybobPresenter.cs deleted file mode 100644 index c4d9dc34c8..0000000000 --- a/src/Avalonia.Controls/Presenters/ThingamybobPresenter.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using Avalonia.Controls.Primitives; -using Avalonia.Media; - -namespace Avalonia.Controls.Presenters -{ - public class ThingamybobPresenter : Decorator, IItemsPresenter, IScrollable - { - private IVirtualizingPanel _panel; - private int _firstIndex; - private int _lastIndex; - - public override void ApplyTemplate() - { - if (_panel == null) - { - _panel = new VirtualizingStackPanel(); - Child = _panel; - CheckPanel(); - } - } - - public IPanel Panel => _panel; - - bool IScrollable.IsLogicalScrollEnabled => true; - Action IScrollable.InvalidateScroll { get; set; } - - Size IScrollable.Extent => new Size(1, 100 * AverageItemSize ); - - Vector IScrollable.Offset - { - get - { - return new Vector(0, (_firstIndex * AverageItemSize) + (_panel?.PixelOffset ?? 0)); - } - - set - { - var count = _lastIndex - _firstIndex; - var firstIndex = (int)(value.Y / AverageItemSize); - var firstIndexChanged = _firstIndex != firstIndex; - _firstIndex = firstIndex; - _lastIndex = _firstIndex + count; - _panel.PixelOffset = value.Y % AverageItemSize; - - if (firstIndexChanged) - { - Renumber(); - } - } - } - - Size IScrollable.Viewport => new Size(1, _panel?.Bounds.Height ?? 0); - Size IScrollable.ScrollSize => new Size(0, 1); - Size IScrollable.PageScrollSize => new Size(0, 1); - - private double AverageItemSize => _panel?.AverageItemSize ?? 1; - - protected override Size ArrangeOverride(Size finalSize) - { - var result = base.ArrangeOverride(finalSize); - CreateItems(); - ((IScrollable)this).InvalidateScroll(); - return result; - } - - private void CreateItems() - { - var randomColor = Color.FromUInt32( - (uint)(0xff000000 + new Random().Next(0xffffff))); - - while (!_panel.IsFull) - { - _panel.Children.Add(new TextBlock - { - Text = "Item " + ++_lastIndex, - Background = new SolidColorBrush(randomColor), - }); - } - } - - private void RemoveItems() - { - var remove = _panel.OverflowCount; - - _panel.Children.RemoveRange( - _panel.Children.Count - remove, - _panel.OverflowCount); - _lastIndex -= remove; - } - - private void Renumber() - { - var index = _firstIndex; - - foreach (TextBlock child in _panel.Children) - { - child.Text = "Item " + ++index; - } - } - - private void CheckPanel() - { - if (!_panel.IsFull) - { - CreateItems(); - } - else if (_panel.OverflowCount > 1) - { - RemoveItems(); - } - } - } -} diff --git a/src/Avalonia.Controls/Thingamybob.cs b/src/Avalonia.Controls/Thingamybob.cs deleted file mode 100644 index 6129b029e8..0000000000 --- a/src/Avalonia.Controls/Thingamybob.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Avalonia.Media; -using System; -using Avalonia.Controls.Primitives; -using Avalonia.Controls.Presenters; - -namespace Avalonia.Controls -{ - public class Thingamybob : Decorator - { - private ScrollViewer _scrollViewer; - private ThingamybobPresenter _presenter; - - public override void ApplyTemplate() - { - if (Child == null) - { - _scrollViewer = new ScrollViewer(); - _presenter = new ThingamybobPresenter(); - _scrollViewer.Content = _presenter; - - Child = _scrollViewer; - } - } - } -}