-
Notifications
You must be signed in to change notification settings - Fork 67
[Experiment] Initial CompositionCollectionView implementation and basic samples #277
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
base: main
Are you sure you want to change the base?
Changes from all commits
d1b9aa1
8a959a9
7cfe44d
6e9dcb6
61be6d3
028c635
11a1a43
d9b54e3
c63d0a4
7ebb3aa
27c94d4
1304e6c
252b5be
efb3d1f
7df0634
0dbd25e
218ee1c
885cf60
cd5c508
b3ddd06
86406e6
39d744e
7c1774a
fa5cc2b
d55fb2b
437667a
cdd5aff
3846011
bb0ef5d
0de0f1e
5f7a680
c0826a3
bf1d7e6
78bd506
75661bc
635fb6d
e8720e2
5f128fb
8d28c32
d582d29
840e331
b194ba7
9aae744
c06af8c
05c6051
790fdd0
8bac431
5421485
fdc41d6
9c2a469
6a0b6c0
4024c1a
5929330
6f978ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
// This file contains directives available to projects that are compiled for multiple frameworks. | ||
// Learn more global using directives at https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/using-directive#global-modifier | ||
|
||
global using System.Runtime.InteropServices.WindowsRuntime; | ||
|
||
global using Windows.Foundation; | ||
global using Windows.Foundation.Collections; | ||
|
||
#if !WINAPPSDK | ||
global using Windows.ApplicationModel; | ||
global using Windows.ApplicationModel.Activation; | ||
|
||
global using Windows.UI.Xaml.Automation; | ||
global using Windows.UI.Xaml.Automation.Peers; | ||
|
||
global using Windows.UI.Xaml; | ||
global using Windows.UI.Xaml.Controls; | ||
global using Windows.UI.Xaml.Controls.Primitives; | ||
global using Windows.UI.Xaml.Data; | ||
global using Windows.UI.Xaml.Input; | ||
global using Windows.UI.Xaml.Markup; | ||
global using Windows.UI.Xaml.Media; | ||
global using Windows.UI.Xaml.Media.Animation; | ||
global using Windows.UI.Xaml.Navigation; | ||
|
||
#else | ||
|
||
global using Microsoft.UI.Xaml.Automation; | ||
global using Microsoft.UI.Xaml.Automation.Peers; | ||
|
||
global using Microsoft.UI.Xaml; | ||
global using Microsoft.UI.Xaml.Controls; | ||
global using Microsoft.UI.Xaml.Controls.Primitives; | ||
global using Microsoft.UI.Xaml.Data; | ||
global using Microsoft.UI.Xaml.Input; | ||
global using Microsoft.UI.Xaml.Markup; | ||
global using Microsoft.UI.Xaml.Media; | ||
global using Microsoft.UI.Xaml.Media.Animation; | ||
global using Microsoft.UI.Xaml.Navigation; | ||
#endif | ||
|
||
global using MUXC = Microsoft.UI.Xaml.Controls; | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes here are going to be a problem/conflict with the work we're doing for #405 and #398. Should just tie-in to clean up needed for #321? |
||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
// This file contains directives available to projects that are compiled for multiple frameworks. | ||
// Learn more global using directives at https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/using-directive#global-modifier | ||
|
||
global using System.Runtime.InteropServices.WindowsRuntime; | ||
|
||
global using Windows.Foundation; | ||
global using Windows.Foundation.Collections; | ||
|
||
#if !WINAPPSDK | ||
global using Windows.ApplicationModel; | ||
global using Windows.ApplicationModel.Activation; | ||
|
||
global using Windows.UI.Xaml.Automation; | ||
global using Windows.UI.Xaml.Automation.Peers; | ||
|
||
global using Windows.UI.Xaml; | ||
global using Windows.UI.Xaml.Controls; | ||
global using Windows.UI.Xaml.Controls.Primitives; | ||
global using Windows.UI.Xaml.Data; | ||
global using Windows.UI.Xaml.Input; | ||
global using Windows.UI.Xaml.Markup; | ||
global using Windows.UI.Xaml.Media; | ||
global using Windows.UI.Xaml.Media.Animation; | ||
global using Windows.UI.Xaml.Navigation; | ||
|
||
global using Windows.UI.Composition; | ||
global using Windows.UI.Composition.Interactions; | ||
global using Windows.UI.Xaml.Hosting; | ||
|
||
#else | ||
|
||
global using Microsoft.UI.Xaml.Automation; | ||
global using Microsoft.UI.Xaml.Automation.Peers; | ||
|
||
global using Microsoft.UI.Xaml; | ||
global using Microsoft.UI.Xaml.Controls; | ||
global using Microsoft.UI.Xaml.Controls.Primitives; | ||
global using Microsoft.UI.Xaml.Data; | ||
global using Microsoft.UI.Xaml.Input; | ||
global using Microsoft.UI.Xaml.Markup; | ||
global using Microsoft.UI.Xaml.Media; | ||
global using Microsoft.UI.Xaml.Media.Animation; | ||
global using Microsoft.UI.Xaml.Navigation; | ||
|
||
global using Microsoft.UI.Composition; | ||
global using Microsoft.UI.Composition.Interactions; | ||
global using Microsoft.UI.Xaml.Hosting; | ||
global using Microsoft.UI; | ||
|
||
#endif | ||
|
||
global using MUXC = Microsoft.UI.Xaml.Controls; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@ECHO OFF | ||
|
||
powershell ..\..\common\ProjectHeads\GenerateSingleSampleHeads.ps1 -componentPath %CD% %* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Page x:Class="CompositionCollectionView.Sample.BasicSample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:labs="using:CommunityToolkit.Labs.WinUI" | ||
xmlns:local="using:CompositionCollectionView.Sample" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel> | ||
<Button x:Name="addButton" | ||
Margin="10"> | ||
Add element | ||
</Button> | ||
<labs:CompositionCollectionView x:Name="compositionCollectionView" | ||
Width="600" | ||
Height="200" /> | ||
</StackPanel> | ||
</Page> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using CommunityToolkit.Labs.WinUI; | ||
using Microsoft.Toolkit.Uwp.UI.Animations.ExpressionsFork; | ||
using System.Xml.Linq; | ||
|
||
#if !WINAPPSDK | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Composition; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using Windows.UI.Xaml.Shapes; | ||
#else | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
#endif | ||
|
||
namespace CompositionCollectionView.Sample | ||
{ | ||
[ToolkitSample(id: nameof(BasicSample), "Simple layout", description: "Displaying elements in a simple layout.")] | ||
public sealed partial class BasicSample : Page | ||
{ | ||
public BasicSample() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
var elements = new Dictionary<uint, object?>() | ||
{ | ||
{ 0, null }, | ||
{ 1, null }, | ||
{ 2, null }, | ||
{ 3, null }, | ||
{ 4, null } | ||
}; | ||
#if !WINAPPSDK | ||
|
||
var layout = new SampleLayout((id) => | ||
new Rectangle() | ||
{ | ||
Width = 100, | ||
Height = 100, | ||
Fill = new SolidColorBrush(Windows.UI.Colors.CornflowerBlue) | ||
}); | ||
compositionCollectionView.SetLayout(layout); | ||
compositionCollectionView.UpdateSource(elements); | ||
|
||
addButton.Click += (object sender, RoutedEventArgs e) => | ||
{ | ||
elements.Add((uint)elements.Count, null); | ||
compositionCollectionView.UpdateSource(elements); | ||
}; | ||
#endif | ||
} | ||
|
||
#if !WINAPPSDK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bit confused by these conditionals in the samples, there's no comment, why is this excluded on the WindowsAppSDK? |
||
public class SampleLayout : CompositionCollectionLayout<uint, object?> | ||
{ | ||
public SampleLayout(Func<uint, FrameworkElement> elementFactory) : base(elementFactory) | ||
{ | ||
} | ||
|
||
public override Vector3Node GetElementPositionNode(ElementReference<uint, object?> element) | ||
{ | ||
return ExpressionFunctions.Vector3(element.Id * 120, 0, 0); | ||
} | ||
|
||
public override ScalarNode GetElementScaleNode(ElementReference<uint, object?> element) => 1; | ||
} | ||
#endif | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should be |
||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using CommunityToolkit.Labs.WinUI; | ||
using Microsoft.Toolkit.Uwp.UI.Animations.ExpressionsFork; | ||
using System.Numerics; | ||
using System.Xml.Linq; | ||
|
||
#if !WINAPPSDK | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI; | ||
using Windows.UI.Composition; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using Windows.UI.Xaml.Shapes; | ||
#else | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
#endif | ||
|
||
namespace CompositionCollectionView.Sample | ||
{ | ||
[ToolkitSample(id: nameof(CanvasSample), "Canvas layout", description: "Displays elements in a 2d canvas, animating between updates.")] | ||
public sealed partial class CanvasSample : Page | ||
{ | ||
public CanvasSample() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
#if !WINAPPSDK | ||
var elements = new Dictionary<uint, Vector2>() | ||
{ | ||
{ 0, Vector2.Zero }, | ||
{ 1, Vector2.Zero }, | ||
{ 2, Vector2.Zero }, | ||
{ 3, Vector2.Zero }, | ||
{ 4, Vector2.Zero } | ||
}; | ||
|
||
var layout = new CanvasLayout((id) => | ||
new Rectangle() | ||
{ | ||
Width = 100, | ||
Height = 100, | ||
Fill = new SolidColorBrush(Windows.UI.Colors.CornflowerBlue), | ||
Stroke = new SolidColorBrush(Colors.Gray), | ||
StrokeThickness = 1 | ||
}); | ||
|
||
compositionCollectionView.SetLayout(layout); | ||
compositionCollectionView.UpdateSource(elements); | ||
|
||
rearrangeButton.Click += (object sender, RoutedEventArgs e) => | ||
{ | ||
var rnd = new Random(); | ||
|
||
for(uint i =0; i< elements.Count; i++) | ||
{ | ||
elements[i] = new Vector2( | ||
(float)(rnd.NextDouble() * compositionCollectionView.ActualWidth), | ||
(float)(rnd.NextDouble() * compositionCollectionView.ActualHeight)); | ||
} | ||
compositionCollectionView.UpdateSource(elements); | ||
}; | ||
#endif | ||
} | ||
|
||
#if !WINAPPSDK | ||
public class CanvasLayout : CompositionCollectionLayout<uint, Vector2> | ||
{ | ||
public CanvasLayout(Func<uint, FrameworkElement> elementFactory) : base(elementFactory) | ||
{ | ||
} | ||
|
||
public override Vector3Node GetElementPositionNode(ElementReference<uint, Vector2> element) | ||
{ | ||
return new Vector3(element.Model.X, element.Model.Y, 0); | ||
} | ||
|
||
protected override ElementTransition GetElementTransitionEasingFunction(ElementReference<uint, Vector2> element) => | ||
new(200, | ||
Window.Current.Compositor.CreateCubicBezierEasingFunction(new Vector2(0.25f, 0.1f), new Vector2(0.25f, 1f))); | ||
} | ||
#endif | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Page x:Class="CompositionCollectionView.Sample.CanvasSample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:labs="using:CommunityToolkit.Labs.WinUI" | ||
xmlns:local="using:CompositionCollectionView.Sample" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel> | ||
<Button x:Name="rearrangeButton" | ||
Margin="10"> | ||
Rearrange | ||
</Button> | ||
<labs:CompositionCollectionView x:Name="compositionCollectionView" | ||
Width="600" | ||
Height="600" /> | ||
</StackPanel> | ||
</Page> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some other non-needed changes here and in the common\test projects