Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use ItemsRepeater as base for ItemsPresenter #2 #4779

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fbc0eac
Renamed some `ItemsRepeater` events to be general use.
grokys Jun 11, 2020
e5babc9
Use ItemsRepeater as base for ItemsPresenter.
grokys Aug 11, 2020
fe9898e
Don't recycle inline items.
grokys Aug 11, 2020
7aafa75
Removed IVirtualizingPanel.
grokys Aug 11, 2020
98a757c
Tweaked selection.
grokys Aug 14, 2020
4e2c128
Don't clear TabOnceActiveElement on clearing.
grokys Sep 7, 2020
6015c7c
Fix remaining failing TreeView tests.
grokys Sep 8, 2020
2f87558
Make DevTools tree update again.
grokys Sep 8, 2020
8d23f44
Update TabOnceActiveElement on prepare.
grokys Sep 8, 2020
9f4de38
Merge branch 'master' into refactor/itemsrepeater-as-itemspresenter2
grokys Sep 17, 2020
6d07d96
Fix some tests broken by merge.
grokys Sep 17, 2020
3050c71
Fix some more tests broken by merge.
grokys Sep 17, 2020
f3f7c3e
Copy ICollection.CopyTo implementation from the BCL.
grokys Sep 17, 2020
ee082de
Short-circuit setting source to current value.
grokys Sep 17, 2020
0b4fd78
Fix more failing tests.
grokys Sep 17, 2020
faf52f7
Fix more failing tests.
grokys Sep 17, 2020
d27c93d
Fix TabControl tests.
grokys Sep 17, 2020
2158b60
Don't try to SelectAll with single selection.
grokys Sep 17, 2020
dbcfa0e
Don't try to realize index -1.
grokys Sep 17, 2020
b524009
Remove unused code and fix nullability.
grokys Sep 17, 2020
858ab27
Merge branch 'master' into refactor/itemsrepeater-as-itemspresenter2
grokys Sep 18, 2020
590e6bf
Update list box page in control catalog.
grokys Sep 18, 2020
cc153a5
Removed unused field.
grokys Sep 18, 2020
01de92c
Make sure inline items are removed...
grokys Sep 21, 2020
4e3b3b9
Merge branch 'master' into refactor/itemsrepeater-as-itemspresenter2
grokys Sep 30, 2020
f322c4d
Merge branch 'master' into refactor/itemsrepeater-as-itemspresenter2
grokys Oct 20, 2020
46e4551
Fix non-compiling tests.
grokys Oct 21, 2020
6b8680a
Merge branch 'master' into refactor/itemsrepeater-as-itemspresenter2
grokys Dec 1, 2020
5124494
Changes missed by merge.
grokys Dec 1, 2020
ddace8b
Make listbox page less confusing for debugging.
grokys Dec 2, 2020
7e1868e
Don't clear non-control items from logical children.
grokys Dec 2, 2020
8be2bca
Initial implementation of CarouselPresenter.
grokys Dec 9, 2020
3943e7c
Handle changing IsVirtualized.
grokys Dec 9, 2020
939e652
Reimplemented page transitions.
grokys Dec 9, 2020
93fe03c
IItemsPresenter.Items -> ItemsView.
grokys Dec 16, 2020
4dc8c08
Merge branch 'master' into refactor/itemsrepeater-as-itemspresenter2
grokys Dec 16, 2020
e7986f2
Fix ncrunch.
grokys Dec 16, 2020
0663bc3
Don't bind ItemTemplate.
grokys Dec 17, 2020
524b940
Remove unused class.
grokys Dec 17, 2020
4551752
Reinstate carousel tests.
grokys Dec 17, 2020
25519ff
Reset containers when ElementFactory changes.
grokys Dec 17, 2020
fd089bf
GetCustomNext can handle the navigation and still return null.
grokys Dec 17, 2020
0a03f71
Port WrapLayout fix.
grokys Dec 17, 2020
703d3bf
Use WrapLayout in TabControl/TabStrip.
grokys Dec 17, 2020
6b30cf9
Fix ComboBox constraint adjustment.
grokys Dec 18, 2020
1154aaf
Merge branch 'master' into refactor/itemsrepeater-as-itemspresenter2
grokys Jan 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ncrunch/Avalonia.Controls.DataGrid.v3.ncrunchproject
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<HiddenComponentWarnings>
<Value>MissingOrIgnoredProjectReference</Value>
</HiddenComponentWarnings>
<InstrumentOutputAssembly>False</InstrumentOutputAssembly>
</Settings>
</ProjectConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>
1 change: 1 addition & 0 deletions .ncrunch/Avalonia.Themes.Default.v3.ncrunchproject
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<HiddenComponentWarnings>
<Value>MissingOrIgnoredProjectReference</Value>
</HiddenComponentWarnings>
<InstrumentOutputAssembly>False</InstrumentOutputAssembly>
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
</Settings>
</ProjectConfiguration>
1 change: 1 addition & 0 deletions .ncrunch/Avalonia.Win32.Interop.v3.ncrunchproject
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<HiddenComponentWarnings>
<Value>MissingOrIgnoredProjectReference</Value>
</HiddenComponentWarnings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
</Settings>
</ProjectConfiguration>
1 change: 1 addition & 0 deletions .ncrunch/Avalonia.Win32.v3.ncrunchproject
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<HiddenComponentWarnings>
<Value>MissingOrIgnoredProjectReference</Value>
</HiddenComponentWarnings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
</Settings>
</ProjectConfiguration>
1 change: 1 addition & 0 deletions .ncrunch/Direct3DInteropSample.v3.ncrunchproject
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<HiddenComponentWarnings>
<Value>MissingOrIgnoredProjectReference</Value>
</HiddenComponentWarnings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
</Settings>
</ProjectConfiguration>
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<AvaloniaPreviewerNetCoreToolPath>$(MSBuildThisFileDirectory)\src\tools\Avalonia.Designer.HostApp\bin\$(Configuration)\netcoreapp2.0\Avalonia.Designer.HostApp.dll</AvaloniaPreviewerNetCoreToolPath>
<!-- https://github.com/dotnet/msbuild/issues/2661 -->
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
<RunApiCompat>false</RunApiCompat>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions samples/ControlCatalog/Pages/CarouselPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</Button>
<Carousel Name="carousel">
<Carousel.PageTransition>
<PageSlide Duration="0.25" Orientation="Vertical" />
<PageSlide Duration="0.25" Orientation="Horizontal" />
</Carousel.PageTransition>
<Image Source="/Assets/delicate-arch-896885_640.jpg"/>
<Image Source="/Assets/hirsch-899118_640.jpg"/>
Expand All @@ -33,7 +33,7 @@

<StackPanel Orientation="Horizontal" Spacing="4">
<TextBlock VerticalAlignment="Center">Orientation</TextBlock>
<ComboBox Name="orientation" SelectedIndex="1" VerticalAlignment="Center">
<ComboBox Name="orientation" SelectedIndex="0" VerticalAlignment="Center">
<ComboBoxItem>Horizontal</ComboBoxItem>
<ComboBoxItem>Vertical</ComboBoxItem>
</ComboBox>
Expand Down
16 changes: 13 additions & 3 deletions samples/ControlCatalog/Pages/ListBoxPage.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ControlCatalog.Pages.ListBoxPage">
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Class="ControlCatalog.Pages.ListBoxPage"
d:DesignWidth="800" d:DesignHeight="600">
<DockPanel>
<StackPanel DockPanel.Dock="Top" Margin="4">
<TextBlock Classes="h1">ListBox</TextBlock>
Expand All @@ -12,12 +14,20 @@
<CheckBox IsChecked="{Binding AlwaysSelected}">AlwaysSelected</CheckBox>
<CheckBox IsChecked="{Binding AutoScrollToSelectedItem}">AutoScrollToSelectedItem</CheckBox>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="4">
<StackPanel DockPanel.Dock="Bottom">
<TextBlock x:Name="realizedCount">Initializing...</TextBlock>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="4" Spacing="4">
<Button Command="{Binding AddItemCommand}">Add</Button>
<Button Command="{Binding RemoveItemCommand}">Remove</Button>
<Button Command="{Binding SelectRandomItemCommand}">Select Random Item</Button>
<ComboBox SelectedIndex="{Binding ItemType}">
<ComboBoxItem>From DataTemplate</ComboBoxItem>
<ComboBoxItem>Inline ListBoxItems</ComboBoxItem>
</ComboBox>
</StackPanel>
<ListBox Items="{Binding Items}"
<ListBox x:Name="listBox"
Items="{Binding Items}"
Selection="{Binding Selection}"
AutoScrollToSelectedItem="{Binding AutoScrollToSelectedItem}"
SelectionMode="{Binding SelectionMode^}"/>
Expand Down
23 changes: 23 additions & 0 deletions samples/ControlCatalog/Pages/ListBoxPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Markup.Xaml;
using ControlCatalog.ViewModels;

namespace ControlCatalog.Pages
{
public class ListBoxPage : UserControl
{
private ListBox _listBox;
private IItemsPresenter _presenter;
private TextBlock _realizedCount;

public ListBoxPage()
{
InitializeComponent();
DataContext = new ListBoxPageViewModel();

_listBox = this.FindControl<ListBox>("listBox");
_realizedCount = this.FindControl<TextBlock>("realizedCount");
LayoutUpdated += OnLayoutUpdated;
}

private void OnLayoutUpdated(object sender, EventArgs e)
{
LayoutUpdated -= OnLayoutUpdated;
_presenter = _listBox.Presenter;
_presenter.VisualChildren.CollectionChanged += (s, e) => UpdateRealizedCount();
UpdateRealizedCount();
}

private void UpdateRealizedCount()
{
_realizedCount.Text = $"{_presenter.VisualChildren.Count} containers realized";
}

private void InitializeComponent()
Expand Down
7 changes: 4 additions & 3 deletions samples/ControlCatalog/SideBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<Setter Property="TabStripPlacement" Value="Left"/>
<Setter Property="Padding" Value="8 0 0 0"/>
<Setter Property="Background" Value="{DynamicResource SystemAccentColor}"/>
<Setter Property="Layout">
<NonVirtualizingStackLayout Orientation="Vertical"/>
</Setter>
<Setter Property="Template">
<ControlTemplate>
<Border
Expand All @@ -28,9 +31,7 @@
DockPanel.Dock="Left">
<ItemsPresenter
Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}">
ItemsView="{TemplateBinding ItemsView}">
</ItemsPresenter>
</ScrollViewer>
<ContentControl Content="{TemplateBinding Tag}" HorizontalContentAlignment="Right" DockPanel.Dock="Bottom"/>
Expand Down
68 changes: 58 additions & 10 deletions samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
Expand All @@ -10,18 +12,30 @@ namespace ControlCatalog.ViewModels
{
public class ListBoxPageViewModel : ViewModelBase
{
private IList _items;
private bool _multiple;
private bool _toggle;
private bool _alwaysSelected;
private bool _autoScrollToSelectedItem = true;
private int _counter;
private ItemTypes _itemType;
private IObservable<SelectionMode> _selectionMode;

public ListBoxPageViewModel()
{
Items = new ObservableCollection<string>(Enumerable.Range(1, 10000).Select(i => GenerateItem()));
this.WhenAnyValue(x => x.ItemType)
.Subscribe(x =>
{
Items = x switch
{
ItemTypes.FromDataTemplate => new ObservableCollection<string>(
Enumerable.Range(0, 10000).Select(i => GenerateContent(i))),
ItemTypes.ListBoxItems => new ObservableCollection<ListBoxItem>(
Enumerable.Range(0, 200).Select(i => GenerateItem(i))),
_ => throw new NotSupportedException(),
};
});

Selection = new SelectionModel<string>();
Selection = new SelectionModel<object>();
Selection.Select(1);

_selectionMode = this.WhenAnyValue(
Expand All @@ -33,7 +47,17 @@ public ListBoxPageViewModel()
(t ? Avalonia.Controls.SelectionMode.Toggle : 0) |
(a ? Avalonia.Controls.SelectionMode.AlwaysSelected : 0));

AddItemCommand = MiniCommand.Create(() => Items.Add(GenerateItem()));
AddItemCommand = MiniCommand.Create(() =>
{
if (ItemType == ItemTypes.FromDataTemplate)
{
Items.Add(GenerateContent(Items.Count));
}
else
{
Items.Add(GenerateItem(Items.Count));
}
});

RemoveItemCommand = MiniCommand.Create(() =>
{
Expand All @@ -49,16 +73,24 @@ public ListBoxPageViewModel()
{
var random = new Random();

using (Selection.BatchUpdate())
if (Items.Count > 0)
{
Selection.Clear();
Selection.Select(random.Next(Items.Count - 1));
using (Selection.BatchUpdate())
{
Selection.Clear();
Selection.Select(random.Next(Items.Count - 1));
}
}
});
}

public ObservableCollection<string> Items { get; }
public SelectionModel<string> Selection { get; }
public IList Items
{
get => _items;
private set => this.RaiseAndSetIfChanged(ref _items, value);
}

public SelectionModel<object> Selection { get; }
public IObservable<SelectionMode> SelectionMode => _selectionMode;

public bool Multiple
Expand All @@ -85,10 +117,26 @@ public bool AutoScrollToSelectedItem
set => this.RaiseAndSetIfChanged(ref _autoScrollToSelectedItem, value);
}

public ItemTypes ItemType
{
get => _itemType;
set => this.RaiseAndSetIfChanged(ref _itemType, value);
}

public MiniCommand AddItemCommand { get; }
public MiniCommand RemoveItemCommand { get; }
public MiniCommand SelectRandomItemCommand { get; }

private string GenerateItem() => $"Item {_counter++.ToString()}";
private string GenerateContent(int index) => $"Item {index}";
private ListBoxItem GenerateItem(int index) => new ListBoxItem
{
Content = "ListBoxItem " + GenerateContent(index)
};

public enum ItemTypes
{
FromDataTemplate,
ListBoxItems,
}
}
}
5 changes: 2 additions & 3 deletions samples/RenderDemo/SideBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
Background="{TemplateBinding Background}">
<ItemsPresenter
Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}">
ItemsView="{TemplateBinding ItemsView}"
Layout="{TemplateBinding Layout}">
</ItemsPresenter>
</ScrollViewer>
<ContentPresenter
Expand Down
6 changes: 0 additions & 6 deletions samples/VirtualizationDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@
Items="{Binding Items}"
Selection="{Binding Selection}"
SelectionMode="Multiple"
VirtualizationMode="{Binding VirtualizationMode}"
ScrollViewer.HorizontalScrollBarVisibility="{Binding HorizontalScrollBarVisibility, Mode=TwoWay}"
ScrollViewer.VerticalScrollBarVisibility="{Binding VerticalScrollBarVisibility, Mode=TwoWay}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="{Binding Orientation}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}" Height="{Binding Height}" TextWrapping="Wrap"/>
Expand Down
10 changes: 0 additions & 10 deletions samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ internal class MainWindowViewModel : ViewModelBase
private ScrollBarVisibility _horizontalScrollBarVisibility = ScrollBarVisibility.Auto;
private ScrollBarVisibility _verticalScrollBarVisibility = ScrollBarVisibility.Auto;
private Orientation _orientation = Orientation.Vertical;
private ItemVirtualizationMode _virtualizationMode = ItemVirtualizationMode.Simple;

public MainWindowViewModel()
{
Expand Down Expand Up @@ -81,15 +80,6 @@ public ScrollBarVisibility VerticalScrollBarVisibility
public IEnumerable<ScrollBarVisibility> ScrollBarVisibilities =>
Enum.GetValues(typeof(ScrollBarVisibility)).Cast<ScrollBarVisibility>();

public ItemVirtualizationMode VirtualizationMode
{
get { return _virtualizationMode; }
set { this.RaiseAndSetIfChanged(ref _virtualizationMode, value); }
}

public IEnumerable<ItemVirtualizationMode> VirtualizationModes =>
Enum.GetValues(typeof(ItemVirtualizationMode)).Cast<ItemVirtualizationMode>();

public MiniCommand AddItemCommand { get; private set; }
public MiniCommand RecreateCommand { get; private set; }
public MiniCommand RemoveItemCommand { get; private set; }
Expand Down
10 changes: 0 additions & 10 deletions src/Avalonia.Controls/Carousel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Avalonia.Animation;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Controls.Utils;
using Avalonia.Input;

namespace Avalonia.Controls
{
Expand All @@ -23,20 +21,12 @@ public class Carousel : SelectingItemsControl
public static readonly StyledProperty<IPageTransition> PageTransitionProperty =
AvaloniaProperty.Register<Carousel, IPageTransition>(nameof(PageTransition));

/// <summary>
/// The default value of <see cref="ItemsControl.ItemsPanelProperty"/> for
/// <see cref="Carousel"/>.
/// </summary>
private static readonly ITemplate<IPanel> PanelTemplate =
new FuncTemplate<IPanel>(() => new Panel());

/// <summary>
/// Initializes static members of the <see cref="Carousel"/> class.
/// </summary>
static Carousel()
{
SelectionModeProperty.OverrideDefaultValue<Carousel>(SelectionMode.AlwaysSelected);
ItemsPanelProperty.OverrideDefaultValue<Carousel>(PanelTemplate);
}

/// <summary>
Expand Down
Loading