Skip to content

Commit

Permalink
Add VirtualPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Mar 20, 2024
1 parent 524d05f commit 9bdfdea
Show file tree
Hide file tree
Showing 16 changed files with 982 additions and 0 deletions.
7 changes: 7 additions & 0 deletions DataBox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBox.DataVirtualization"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBoxDataVirtualizationDemo", "samples\DataBoxDataVirtualizationDemo\DataBoxDataVirtualizationDemo.csproj", "{51696845-5450-4A14-9368-E1063B6B14B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualPanel", "src\VirtualPanel\VirtualPanel.csproj", "{2C2535BC-38DB-4FFF-BD30-ABAED465E7D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -89,6 +91,10 @@ Global
{51696845-5450-4A14-9368-E1063B6B14B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51696845-5450-4A14-9368-E1063B6B14B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51696845-5450-4A14-9368-E1063B6B14B5}.Release|Any CPU.Build.0 = Release|Any CPU
{2C2535BC-38DB-4FFF-BD30-ABAED465E7D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C2535BC-38DB-4FFF-BD30-ABAED465E7D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C2535BC-38DB-4FFF-BD30-ABAED465E7D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C2535BC-38DB-4FFF-BD30-ABAED465E7D7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{17E6165A-4614-435A-8BBE-55A8C850F21B} = {BFAAFDC6-9A28-4F70-9C21-F6DF50786C70}
Expand All @@ -100,5 +106,6 @@ Global
{185AA19E-8CAC-4539-BD28-8199E348AC40} = {BFAAFDC6-9A28-4F70-9C21-F6DF50786C70}
{8AD8D915-14C1-49E5-AB33-792C63DF2379} = {D7275F04-303E-4385-B806-08726C572D6D}
{51696845-5450-4A14-9368-E1063B6B14B5} = {3B564AD4-C507-43DC-8711-38320FB3B679}
{2C2535BC-38DB-4FFF-BD30-ABAED465E7D7} = {D7275F04-303E-4385-B806-08726C572D6D}
EndGlobalSection
EndGlobal
Binary file not shown.
24 changes: 24 additions & 0 deletions samples/VirtualPanelDemo.NetCore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;

namespace VirtualPanelDemo.NetCore
{
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
}
}
37 changes: 37 additions & 0 deletions samples/VirtualPanelDemo.NetCore/VirtualPanelDemo.NetCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU' Or '$(Configuration)|$(Platform)'=='Debug|x64'">
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU' Or '$(Configuration)|$(Platform)'=='Release|x64'">
<OutputType>WinExe</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>

<Import Project="..\..\build\Base.props" />
<Import Project="..\..\build\ReferenceAssemblies.props" />
<Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Desktop.props" />
<Import Project="..\..\build\Avalonia.Diagnostics.props" />
<Import Project="..\..\build\Avalonia.ReactiveUI.props" />

<ItemGroup>
<ProjectReference Include="..\..\src\DataVirtualization\DataVirtualization.csproj" />
<ProjectReference Include="..\..\src\VirtualPanel\VirtualPanel.csproj" />
<ProjectReference Include="..\VirtualPanelDemo\VirtualPanelDemo.csproj" />
</ItemGroup>

<ItemGroup>
<UpToDateCheckInput Remove="Views\MainWindow.axaml" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions samples/VirtualPanelDemo/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="VirtualPanelDemo.App">
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
27 changes: 27 additions & 0 deletions samples/VirtualPanelDemo/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace VirtualPanelDemo;

public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime single)
{
single.MainView = new MainView();
}

base.OnFrameworkInitializationCompleted();
}
}
63 changes: 63 additions & 0 deletions samples/VirtualPanelDemo/MainView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dv="clr-namespace:DataVirtualization;assembly=DataVirtualization"
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
xmlns:vm="clr-namespace:VirtualPanelDemo.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="VirtualPanelDemo.MainView"
x:DataType="vm:MainWindowViewModel" x:CompileBindings="True">

<DockPanel>

<DockPanel DockPanel.Dock="Top" HorizontalAlignment="Center" Background="Gray" x:CompileBindings="False"
IsVisible="False">
<TextBlock Margin="6,0,6,0" Text="{Binding #ScrollViewer.Extent, StringFormat={}Extent: {0}}" DockPanel.Dock="Top" />
<TextBlock Margin="6,0,6,0" Text="{Binding #ScrollViewer.Viewport, StringFormat={}Viewport: {0}}" DockPanel.Dock="Top" />
<TextBlock Margin="6,0,6,0" Text="{Binding #ScrollViewer.Offset, StringFormat={}Offset: {0}}" DockPanel.Dock="Top" />
<TextBlock Margin="6,0,6,0" Text="{Binding Count, StringFormat={}Count: {0}}" DockPanel.Dock="Top" />
<TextBlock Margin="6,0,6,0" Text="{Binding ItemHeight, StringFormat={}ItemHeight: {0}}" DockPanel.Dock="Top" />
</DockPanel>

<ScrollViewer Name="ScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">

<ScrollViewer.Styles>
<!--<Style Selector="VirtualPanel > ContentControl">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="VirtualPanel > ContentControl:nth-child(2n)">
<Setter Property="Background" Value="#fff8f8f8"/>
</Style>-->
<Style Selector="VirtualPanel > ContentControl:pointerover">
<Setter Property="Background" Value="#ffe4e4e4"/>
</Style>
</ScrollViewer.Styles>

<VirtualPanel ItemsSource="{Binding Items}"
ItemHeight="{Binding ItemHeight}"
ItemWidth="{Binding ItemWidth}"
ScrollMode="Smooth"
Layout="Wrap"
VerticalAlignment="Top"
Name="VirtualPanel">
<VirtualPanel.ItemTemplate>
<DataTemplate>
<DataTemplate.DataType>
<x:Type TypeName="dv:DataWrapper" x:TypeArguments="sys:String" />
</DataTemplate.DataType>
<Panel Background="#fff8f8f8"
Margin="2" >
<TextBlock Text="{Binding Data}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Panel>
</DataTemplate>
</VirtualPanel.ItemTemplate>
</VirtualPanel>

</ScrollViewer>

</DockPanel>

</UserControl>
32 changes: 32 additions & 0 deletions samples/VirtualPanelDemo/MainView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using VirtualPanelDemo.ViewModels;

namespace VirtualPanelDemo;

public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();

var vm = new MainWindowViewModel(2_000_000_000, 100, 100, 100);

DataContext = vm;

var vp = this.FindControl<VirtualPanel.VirtualPanel>("VirtualPanel");

if (vm.Items is { })
{
vm.Items.CollectionChanged += (_, _) =>
{
vp.InvalidateMeasure();
};
}
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
13 changes: 13 additions & 0 deletions samples/VirtualPanelDemo/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VirtualPanelDemo"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="635"
WindowState="Normal" WindowStartupLocation="CenterScreen"
Width="800" Height="635"
UseLayoutRounding="True"
x:Class="VirtualPanelDemo.MainWindow"
Title="VirtualPanel Demo">
<local:MainView/>
</Window>
25 changes: 25 additions & 0 deletions samples/VirtualPanelDemo/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Rendering;
using VirtualPanelDemo.ViewModels;

namespace VirtualPanelDemo;

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
//RendererDiagnostics.DebugOverlays = RendererDebugOverlays.Fps | RendererDebugOverlays.LayoutTimeGraph | RendererDebugOverlays.RenderTimeGraph;
RendererDiagnostics.DebugOverlays = RendererDebugOverlays.Fps;
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
36 changes: 36 additions & 0 deletions samples/VirtualPanelDemo/ViewModels/ItemProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using DataVirtualization;

namespace VirtualPanelDemo.ViewModels
{
public class ItemProvider : IItemsProvider<string>
{
private readonly int _count;

public ItemProvider(int count)
{
_count = count;
}

public int FetchCount()
{
return _count;
}

public IList<string> FetchRange(int startIndex, int pageCount, out int overallCount)
{
var result = new List<string>();
var endIndex = startIndex + pageCount;

overallCount = _count;

for (var i = startIndex; i < endIndex; i++)
{
//result.Add($"Item {i}");
result.Add($"{i}");
}

return result;
}
}
}
44 changes: 44 additions & 0 deletions samples/VirtualPanelDemo/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using DataVirtualization;
using ReactiveUI;

namespace VirtualPanelDemo.ViewModels;

public class MainWindowViewModel : ReactiveObject
{
private AsyncVirtualizingCollection<string>? _items;
private double _itemHeight;
private double _itemWidth;

public AsyncVirtualizingCollection<string>? Items
{
get => _items;
set => this.RaiseAndSetIfChanged(ref _items, value);
}

public double ItemHeight
{
get => _itemHeight;
set => this.RaiseAndSetIfChanged(ref _itemHeight, value);
}

public double ItemWidth
{
get => _itemWidth;
set => this.RaiseAndSetIfChanged(ref _itemWidth, value);
}

public int Count { get; }

public void RaiseCountChanged()
{
this.RaisePropertyChanged(nameof(Count));
}

public MainWindowViewModel(int count, int pageSize, int itemHeight, int itemWidth)
{
Items = new AsyncVirtualizingCollection<string>(new ItemProvider(count), pageSize, 5000);
ItemHeight = itemHeight;
ItemWidth = itemWidth;
Count = count;
}
}
25 changes: 25 additions & 0 deletions samples/VirtualPanelDemo/VirtualPanelDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>

<Import Project="..\..\build\Base.props" />
<Import Project="..\..\build\ReferenceAssemblies.props" />
<Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Themes.Fluent.props" />
<Import Project="..\..\build\Avalonia.Diagnostics.props" />
<Import Project="..\..\build\Avalonia.ReactiveUI.props" />

<ItemGroup>
<ProjectReference Include="..\..\src\DataVirtualization\DataVirtualization.csproj" />
<ProjectReference Include="..\..\src\VirtualPanel\VirtualPanel.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions src/VirtualPanel/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Avalonia.Metadata;

[assembly: XmlnsDefinition("https://github.com/avaloniaui", "VirtualPanel")]
Loading

0 comments on commit 9bdfdea

Please sign in to comment.