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

Update WinUI 2 and Windows Community Toolkit #102

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Brainf_ckSharp.Services;
using Brainf_ckSharp.Shared.Constants;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
Expand All @@ -20,13 +21,22 @@ public sealed partial class AboutSubPageViewModel : ObservableObject
/// </summary>
private readonly IGitHubService gitHubService;

/// <summary>
/// The <see cref="IGitHubService"/> instance currently in use
/// </summary>
private readonly ISystemInformationService systemInformationService;

/// <summary>
/// Creates a new <see cref="AboutSubPageViewModel"/> instance
/// </summary>
/// <param name="gitHubService">The <see cref="IGitHubService"/> instance to use</param>
public AboutSubPageViewModel(IGitHubService gitHubService)
/// <param name="systemInformationService">The <see cref="ISystemInformationService"/> instance to use</param>
public AboutSubPageViewModel(
IGitHubService gitHubService,
ISystemInformationService systemInformationService)
{
this.gitHubService = gitHubService;
this.systemInformationService = systemInformationService;
}

/// <summary>
Expand All @@ -39,6 +49,11 @@ public AboutSubPageViewModel(IGitHubService gitHubService)
/// </summary>
public string GitCommit => ThisAssembly.Git.Commit;

/// <summary>
/// Gets the current app version.
/// </summary>
public string AppVersion => this.systemInformationService.ApplicationVersion;

/// <summary>
/// Gets the name of the current build configuration
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using Windows.UI.Xaml.Shapes;
using Brainf_ckSharp.Uwp.Themes;
using Brainf_ckSharp.Uwp.Themes.Enums;
using Microsoft.Graphics.Canvas.UI.Xaml;
using CommunityToolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI;
using Microsoft.Toolkit.Uwp.UI.Animations;
using CommunityToolkit.WinUI;
using CommunityToolkit.WinUI.Animations;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

#nullable enable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<UserControl
<UserControl
x:Class="Brainf_ckSharp.Uwp.Controls.Ide.Brainf_ckIde"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ide="using:Brainf_ckSharp.Uwp.Controls.Ide"
xmlns:xaml="using:Microsoft.Graphics.Canvas.UI.Xaml"
xmlns:ui="using:Microsoft.Toolkit.Uwp.UI"
xmlns:ui="using:CommunityToolkit.WinUI"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Brainf_ckSharp.Constants;
using Brainf_ckSharp.Uwp.Controls.Ide.Helpers;
using CommunityToolkit.HighPerformance;
using Microsoft.Toolkit.Uwp.UI.Animations;
using CommunityToolkit.WinUI.Animations;

namespace Brainf_ckSharp.Uwp.Controls.Ide;

Expand All @@ -33,7 +33,7 @@ public Brainf_ckIde()
private void Brainf_ckIde_Loaded(object sender, RoutedEventArgs e)
{
_ = this.CodeEditBox.ContentScroller!.StartExpressionAnimation(this.LineBlock, Axis.Y, VisualProperty.Offset);
_ = this.CodeEditBox.ContentScroller.StartExpressionAnimation(this.IdeOverlaysCanvas, Axis.Y, VisualProperty.Offset);
_ = this.CodeEditBox.ContentScroller!.StartExpressionAnimation(this.IdeOverlaysCanvas, Axis.Y, VisualProperty.Offset);

this.CodeEditBox.ContentElement!.SizeChanged += Brainf_ckIde_SizeChanged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@
<EmbeddedResource Include="Properties\Brainf_ckSharp.Uwp.Controls.Ide.rd.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Uwp.Animations">
<Version>8.1.240821</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
<Version>7.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.5.0</Version>
<Version>2.8.6</Version>
</PackageReference>
<PackageReference Include="Win2D.uwp">
<Version>1.27.1</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/Brainf_ckSharp.Uwp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
using Brainf_ckSharp.Shared.Constants;
using Brainf_ckSharp.Shared.ViewModels.Views;
using Brainf_ckSharp.Uwp.Controls.SubPages.Host;
using CommunityToolkit.WinUI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Uwp.UI;

#nullable enable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -7,7 +7,7 @@
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Media;
using Brainf_ckSharp.Models;
using Microsoft.Toolkit.Uwp;
using CommunityToolkit.WinUI;

#nullable enable

Expand Down Expand Up @@ -48,8 +48,8 @@ public static void SetStackTrace(Paragraph element, IReadOnlyList<string>? value
new(Array.Empty<FunctionDefinition>(), OnStackTracePropertyChanged));

// Localized resources
private static readonly string At = "StackTrace/At".GetLocalized();
private static readonly string Frames = "StackTrace/Frames".GetLocalized();
private static readonly string At = "StackTrace/At".GetLocalized()!;
private static readonly string Frames = "StackTrace/Frames".GetLocalized()!;

/// <summary>
/// Updates the UI when <see cref="StackTraceProperty"/> changes
Expand All @@ -70,6 +70,7 @@ private static void OnStackTracePropertyChanged(DependencyObject d, DependencyPr
}

int i = 0;

foreach ((string Item, int Occurrences, int Length) entry in CompressStackTrace(value))
{
if (i++ > 0)
Expand All @@ -84,11 +85,14 @@ private static void OnStackTracePropertyChanged(DependencyObject d, DependencyPr
Foreground = new SolidColorBrush(Colors.DimGray),
FontSize = @this.FontSize - 1
});

@this.Inlines.Add(new LineBreak());

// Add the formatted call line
Span line = new();

SetSource(line, entry.Item);

@this.Inlines.Add(line);
}
}
Expand All @@ -101,12 +105,14 @@ private static void OnStackTracePropertyChanged(DependencyObject d, DependencyPr
{
int i = 0;
List<(int Length, int Occurrences)> info = [];

while (i < frames.Count)
{
for (int step = 1; step < 5 && i + (step * 2) - 1 < frames.Count; step++)
{
// Find a valid sub-pattern of a given length
bool valid = true;

for (int j = 0; j < step; j++)
{
if (!frames[i + j].Equals(frames[i + step + j]))
Expand All @@ -123,9 +129,11 @@ private static void OnStackTracePropertyChanged(DependencyObject d, DependencyPr

// Check of many times the pattern repeats
int occurrences = 2;

for (int j = i + (step * 2); j + step - 1 < frames.Count; j += step)
{
valid = true;

for (int k = 0; k < step; k++)
{
if (!frames[i + k].Equals(frames[j + k]))
Expand Down Expand Up @@ -155,22 +163,26 @@ private static void OnStackTracePropertyChanged(DependencyObject d, DependencyPr
{
(int Length, int Occurrences) best = info.OrderByDescending(item => item.Length * item.Occurrences).ThenBy(item => item.Length).First();
StringBuilder builder = new();

for (int j = 0; j < best.Length; j++)
{
builder.Append(frames[i + j]);
_ = builder.Append(frames[i + j]);
}

string call = builder.ToString();

if (call.Contains(':'))
{
// Only aggregate recursive calls
yield return (call, best.Occurrences, best.Length);

i += best.Length * best.Occurrences;
}
else
{
// The repeated loops are just user code
yield return (frames[i], 1, 1);

i += 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Windows.UI;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Media;
Expand All @@ -9,9 +9,9 @@
using Brainf_ckSharp.Shared.Models.Ide.Views;
using Brainf_ckSharp.Uwp.Converters.Console;
using Brainf_ckSharp.Uwp.Themes;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Uwp;
using CommunityToolkit.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using CommunityToolkit.WinUI;

#nullable enable

Expand Down Expand Up @@ -57,12 +57,12 @@ public static void SetSection(Span element, IdeResultWithSectionInfo? value)
new(DependencyProperty.UnsetValue, OnSectionPropertyChanged));

// Localized resources
private static readonly string AtPosition = "IdeResults/AtPosition".GetLocalized();
private static readonly string StackFrames = "IdeResults/StackFrames".GetLocalized();
private static readonly string DefinedFunctions = "IdeResults/DefinedFunctions".GetLocalized();
private static readonly string Operators = "IdeResults/Operators".GetLocalized();
private static readonly string MemoryCells = "IdeResults/MemoryCells".GetLocalized();
private static readonly string OperatorsInTime = "IdeResults/OperatorsInTime".GetLocalized();
private static readonly string AtPosition = "IdeResults/AtPosition".GetLocalized()!;
private static readonly string StackFrames = "IdeResults/StackFrames".GetLocalized()!;
private static readonly string DefinedFunctions = "IdeResults/DefinedFunctions".GetLocalized()!;
private static readonly string Operators = "IdeResults/Operators".GetLocalized()!;
private static readonly string MemoryCells = "IdeResults/MemoryCells".GetLocalized()!;
private static readonly string OperatorsInTime = "IdeResults/OperatorsInTime".GetLocalized()!;

/// <summary>
/// Updates the UI when <see cref="SectionProperty"/> changes
Expand Down
12 changes: 8 additions & 4 deletions src/Brainf_ckSharp.Uwp/AttachedProperties/ListViewBaseHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Specialized;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Toolkit.Uwp.UI;
using CommunityToolkit.Diagnostics;
using CommunityToolkit.WinUI;

#nullable enable

Expand Down Expand Up @@ -64,14 +64,16 @@ private static void OnIsAutoScrollEnabledPropertyChanged(DependencyObject d, Dep
// Remove the old handler, if necessary
if (oldValue is not null)
{
ControlsMap.Remove(oldValue);
_ = ControlsMap.Remove(oldValue);

oldValue.CollectionChanged -= INotifyCollectionChanged_CollectionChanged;
}

// Register the new collection, if needed
if (newValue is not null)
{
ControlsMap.Add(newValue, @this);

newValue.CollectionChanged += INotifyCollectionChanged_CollectionChanged;
}
}
Expand All @@ -95,7 +97,9 @@ private static async void INotifyCollectionChanged_CollectionChanged(object send

// Wait for the new item to be displayed, then scroll down
await Task.Delay(250);

ScrollViewer scroller = control.FindDescendant<ScrollViewer>()!;
scroller?.ChangeView(null, scroller.ScrollableHeight, null, false);

_ = scroller?.ChangeView(null, scroller.ScrollableHeight, null, false);
}
}
30 changes: 15 additions & 15 deletions src/Brainf_ckSharp.Uwp/Behaviors/LockedPivotBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CommunityToolkit.Diagnostics;
using Microsoft.Toolkit.Uwp.UI;
using CommunityToolkit.Diagnostics;
using CommunityToolkit.WinUI;
using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -17,7 +17,7 @@ public sealed class LockedPivotBehavior : Behavior<Pivot>
/// <summary>
/// The root <see cref="ScrollViewer"/> for the associated <see cref="Pivot"/>.
/// </summary>
private ScrollViewer? _scrollViewer;
private ScrollViewer? scrollViewer;

/// <inheritdoc/>
protected override void OnAttached()
Expand All @@ -34,13 +34,13 @@ protected override void OnDetaching()

AssociatedObject.Loaded -= AssociatedObject_Loaded;

if (this._scrollViewer is not null)
if (this.scrollViewer is not null)
{
this._scrollViewer!.PointerEntered -= Scroller_PointerIn;
this._scrollViewer.PointerMoved -= Scroller_PointerIn;
this._scrollViewer.PointerExited -= Scroller_PointerOut;
this._scrollViewer.PointerReleased -= Scroller_PointerOut;
this._scrollViewer.PointerCaptureLost -= Scroller_PointerOut;
this.scrollViewer!.PointerEntered -= Scroller_PointerIn;
this.scrollViewer.PointerMoved -= Scroller_PointerIn;
this.scrollViewer.PointerExited -= Scroller_PointerOut;
this.scrollViewer.PointerReleased -= Scroller_PointerOut;
this.scrollViewer.PointerCaptureLost -= Scroller_PointerOut;
}
}

Expand All @@ -54,14 +54,14 @@ private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
return;
}

this._scrollViewer = scroller;
this.scrollViewer = scroller;

// Add the handlers to disable the swipe gestures
this._scrollViewer.PointerEntered += Scroller_PointerIn;
this._scrollViewer.PointerMoved += Scroller_PointerIn;
this._scrollViewer.PointerExited += Scroller_PointerOut;
this._scrollViewer.PointerReleased += Scroller_PointerOut;
this._scrollViewer.PointerCaptureLost += Scroller_PointerOut;
this.scrollViewer.PointerEntered += Scroller_PointerIn;
this.scrollViewer.PointerMoved += Scroller_PointerIn;
this.scrollViewer.PointerExited += Scroller_PointerOut;
this.scrollViewer.PointerReleased += Scroller_PointerOut;
this.scrollViewer.PointerCaptureLost += Scroller_PointerOut;
}

// Disables the swipe gesture for the keyboard pivot (swiping that pivot causes the app to crash)
Expand Down
17 changes: 10 additions & 7 deletions src/Brainf_ckSharp.Uwp/Brainf_ckSharp.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,23 @@
<PackageReference Include="CommunityToolkit.Labs.Extensions.DependencyInjection">
<Version>0.1.240911-build.1751</Version>
</PackageReference>
<PackageReference Include="CommunityToolkit.Uwp.Controls.Primitives">
<Version>8.1.240821</Version>
</PackageReference>
<PackageReference Include="CommunityToolkit.Uwp.Converters">
<Version>8.1.240821</Version>
</PackageReference>
<PackageReference Include="CommunityToolkit.Uwp.Media">
<Version>8.1.240821</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>8.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
<Version>7.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Media">
<Version>7.1.3</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.5.0</Version>
<Version>2.8.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
<Version>2.0.1</Version>
Expand Down
Loading