Merge branch 'master' into winui

This commit is contained in:
Alexandre Zollinger Chohfi 2021-04-21 10:11:25 -07:00
Родитель 2216723765 385e4fb5bd
Коммит fedf3f9834
9 изменённых файлов: 117 добавлений и 63 удалений

Просмотреть файл

@ -9,10 +9,10 @@ using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using CommunityToolkit.Mvvm.Messaging.Internals;
using Microsoft.Collections.Extensions;
#if NETSTANDARD2_1
using RecipientsTable = System.Runtime.CompilerServices.ConditionalWeakTable<object, Microsoft.Collections.Extensions.IDictionarySlim>;
#else
#if NETSTANDARD2_0
using RecipientsTable = CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger.ConditionalWeakTable<object, Microsoft.Collections.Extensions.IDictionarySlim>;
#else
using RecipientsTable = System.Runtime.CompilerServices.ConditionalWeakTable<object, Microsoft.Collections.Extensions.IDictionarySlim>;
#endif
namespace CommunityToolkit.Mvvm.Messaging
@ -288,7 +288,7 @@ namespace CommunityToolkit.Mvvm.Messaging
}
}
#if !NETSTANDARD2_1
#if NETSTANDARD2_0
/// <summary>
/// A wrapper for <see cref="System.Runtime.CompilerServices.ConditionalWeakTable{TKey,TValue}"/>
/// that backports the enumerable support to .NET Standard 2.0 through an auxiliary list.
@ -470,7 +470,7 @@ namespace CommunityToolkit.Mvvm.Messaging
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ArrayPoolBufferWriter<T> Create()
{
return new ArrayPoolBufferWriter<T> { array = ArrayPool<T>.Shared.Rent(DefaultInitialBufferSize) };
return new() { array = ArrayPool<T>.Shared.Rent(DefaultInitialBufferSize) };
}
/// <summary>

Просмотреть файл

@ -8,7 +8,7 @@
Margin="50,100,20,20"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ui:Mouse.Cursor="UniversalNo"
ui:FrameworkElementExtensions.Cursor="UniversalNo"
Background="DeepSkyBlue">
<TextBlock Margin="4"
HorizontalAlignment="Center"
@ -21,7 +21,7 @@
Margin="20"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ui:Mouse.Cursor="Wait"
ui:FrameworkElementExtensions.Cursor="Wait"
Background="Orange">
<TextBlock Margin="4"
HorizontalAlignment="Center"
@ -37,7 +37,7 @@
<Button Margin="20,290,20,20"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ui:Mouse.Cursor="Hand"
ui:FrameworkElementExtensions.Cursor="Hand"
Content="Button with Hand cursor, just like on web" />
</Grid>
</Page>
</Page>

Просмотреть файл

@ -12,7 +12,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
private readonly List<IDrawable> _drawableList;
private readonly TextDrawable _drawable;
public InfiniteCanvasCreateTextBoxCommand(List<IDrawable> drawableList, double x, double y, double width, double height, int textFontSize, string text, Color color, bool isBold, bool isItalic)
public InfiniteCanvasCreateTextBoxCommand(List<IDrawable> drawableList, double x, double y, double width, double height, float textFontSize, string text, Color color, bool isBold, bool isItalic)
{
_drawable = new TextDrawable(
x,

Просмотреть файл

@ -79,7 +79,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
ExecuteCommand(command);
}
internal void ExecuteCreateTextBox(double x, double y, double width, double height, int textFontSize, string text, Color color, bool isBold, bool isItalic)
internal void ExecuteCreateTextBox(double x, double y, double width, double height, float textFontSize, string text, Color color, bool isBold, bool isItalic)
{
var command = new InfiniteCanvasCreateTextBoxCommand(_drawableList, x, y, width, height, textFontSize, text, color, isBold, isItalic);
ExecuteCommand(command);

Просмотреть файл

@ -28,28 +28,20 @@ namespace CommunityToolkit.WinUI.UI.Controls
"Right",
"Up",
"Left",
"Down"
"Down",
"Enter"
};
private Point _lastInputPoint;
private TextDrawable SelectedTextDrawable => _drawingSurfaceRenderer.GetSelectedTextDrawable();
private int _lastValidTextFontSizeValue = DefaultFontValue;
private float _textFontSize = DefaultFontValue;
private int TextFontSize
private void SetFontSize(float newSize)
{
get
{
if (!string.IsNullOrWhiteSpace(_canvasTextBoxFontSizeTextBox.Text) &&
Regex.IsMatch(_canvasTextBoxFontSizeTextBox.Text, "^[0-9]*$"))
{
var fontSize = int.Parse(_canvasTextBoxFontSizeTextBox.Text);
_lastValidTextFontSizeValue = fontSize;
}
return _lastValidTextFontSizeValue;
}
_textFontSize = newSize;
_canvasTextBox.UpdateFontSize(newSize);
}
private void InkScrollViewer_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
@ -93,13 +85,34 @@ namespace CommunityToolkit.WinUI.UI.Controls
}
}
private void CanvasTextBoxFontSizeTextBox_TextChanged(object sender, TextChangedEventArgs e)
private void CanvasComboBoxFontSizeTextBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_canvasTextBox.UpdateFontSize(TextFontSize);
if (SelectedTextDrawable != null)
if (sender is ComboBox s
&& s.SelectedItem is ComboBoxItem selectedItem
&& selectedItem.Content is string selectedText
&& float.TryParse(selectedText, out var sizeNumb))
{
_drawingSurfaceRenderer.ExecuteUpdateTextBoxFontSize(TextFontSize);
ReDrawCanvas();
SetFontSize(sizeNumb);
if (SelectedTextDrawable != null)
{
_drawingSurfaceRenderer.ExecuteUpdateTextBoxFontSize(sizeNumb);
ReDrawCanvas();
}
}
}
private void CanvasComboBoxFontSizeTextBox_TextSubmitted(ComboBox sender, ComboBoxTextSubmittedEventArgs args)
{
if (float.TryParse(args.Text, out var size))
{
SetFontSize(size);
if (SelectedTextDrawable != null)
{
_drawingSurfaceRenderer.ExecuteUpdateTextBoxFontSize(size);
ReDrawCanvas();
}
}
}
@ -147,20 +160,22 @@ namespace CommunityToolkit.WinUI.UI.Controls
ReDrawCanvas();
return;
}
else
{
_drawingSurfaceRenderer.ExecuteCreateTextBox(
_lastInputPoint.X,
_lastInputPoint.Y,
_canvasTextBox.GetEditZoneWidth(),
_canvasTextBox.GetEditZoneHeight(),
_textFontSize,
text,
_canvasTextBoxColorPicker.Color,
_canvasTextBoxBoldButton.IsChecked ?? false,
_canvasTextBoxItalicButton.IsChecked ?? false);
_drawingSurfaceRenderer.ExecuteCreateTextBox(
_lastInputPoint.X,
_lastInputPoint.Y,
_canvasTextBox.GetEditZoneWidth(),
_canvasTextBox.GetEditZoneHeight(),
TextFontSize,
text,
_canvasTextBoxColorPicker.Color,
_canvasTextBoxBoldButton.IsChecked ?? false,
_canvasTextBoxItalicButton.IsChecked ?? false);
ReDrawCanvas();
_drawingSurfaceRenderer.UpdateSelectedTextDrawable();
ReDrawCanvas();
_drawingSurfaceRenderer.UpdateSelectedTextDrawable();
}
}
private void InkScrollViewer_PointerPressed(object sender, PointerRoutedEventArgs e)
@ -180,20 +195,17 @@ namespace CommunityToolkit.WinUI.UI.Controls
Canvas.SetLeft(_canvasTextBox, SelectedTextDrawable.Bounds.X);
Canvas.SetTop(_canvasTextBox, SelectedTextDrawable.Bounds.Y);
_canvasTextBox.UpdateFontSize(SelectedTextDrawable.FontSize);
_canvasTextBox.UpdateFontStyle(SelectedTextDrawable.IsItalic);
_canvasTextBox.UpdateFontWeight(SelectedTextDrawable.IsBold);
// Updating toolbar
_canvasTextBoxColorPicker.Color = SelectedTextDrawable.TextColor;
_canvasTextBoxFontSizeTextBox.Text = SelectedTextDrawable.FontSize.ToString();
_canvasTextBoxBoldButton.IsChecked = SelectedTextDrawable.IsBold;
_canvasTextBoxItalicButton.IsChecked = SelectedTextDrawable.IsItalic;
return;
}
_canvasTextBox.UpdateFontSize(TextFontSize);
_canvasTextBox.UpdateFontStyle(_canvasTextBoxItalicButton.IsChecked ?? false);
_canvasTextBox.UpdateFontWeight(_canvasTextBoxBoldButton.IsChecked ?? false);
@ -212,7 +224,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
_canvasTextBox.Clear();
}
private void CanvasTextBoxFontSizeTextBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
private void CanvasComboBoxFontSizeTextBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
if (_allowedCommands.Contains(e.Key.ToString()))
{

Просмотреть файл

@ -21,7 +21,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
/// </summary>
[TemplatePart(Name = CanvasTextBoxToolsName, Type = typeof(StackPanel))]
[TemplatePart(Name = CanvasTextBoxColorPickerName, Type = typeof(Microsoft.UI.Xaml.Controls.ColorPicker))]
[TemplatePart(Name = CanvasTextBoxFontSizeTextBoxName, Type = typeof(TextBox))]
[TemplatePart(Name = CanvasComboBoxFontSizeTextBoxName, Type = typeof(TextBox))]
[TemplatePart(Name = CanvasTextBoxItalicButtonName, Type = typeof(ToggleButton))]
[TemplatePart(Name = CanvasTextBoxBoldButtonName, Type = typeof(ToggleButton))]
[TemplatePart(Name = DrawingSurfaceRendererName, Type = typeof(InfiniteCanvasVirtualDrawingSurface))]
@ -47,7 +47,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
private const string CanvasTextBoxToolsName = "CanvasTextBoxTools";
private const string CanvasTextBoxColorPickerName = "CanvasTextBoxColorPicker";
private const string CanvasTextBoxFontSizeTextBoxName = "CanvasTextBoxFontSizeTextBox";
private const string CanvasComboBoxFontSizeTextBoxName = "CanvasComboBoxFontSizeTextBox";
private const string CanvasTextBoxItalicButtonName = "CanvasTextBoxItalicButton";
private const string CanvasTextBoxBoldButtonName = "CanvasTextBoxBoldButton";
private const string DrawingSurfaceRendererName = "DrawingSurfaceRenderer";
@ -75,7 +75,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
private StackPanel _canvasTextBoxTools;
private Microsoft.UI.Xaml.Controls.ColorPicker _canvasTextBoxColorPicker;
private TextBox _canvasTextBoxFontSizeTextBox;
private ComboBox _canvasComboBoxFontSizeTextBox;
private ToggleButton _canvasTextBoxItalicButton;
private ToggleButton _canvasTextBoxBoldButton;
private Button _undoButton;
@ -248,7 +248,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
{
_canvasTextBoxTools = (StackPanel)GetTemplateChild(CanvasTextBoxToolsName);
this._canvasTextBoxColorPicker = (Microsoft.UI.Xaml.Controls.ColorPicker)GetTemplateChild(CanvasTextBoxColorPickerName);
_canvasTextBoxFontSizeTextBox = (TextBox)GetTemplateChild(CanvasTextBoxFontSizeTextBoxName);
_canvasComboBoxFontSizeTextBox = (ComboBox)GetTemplateChild(CanvasComboBoxFontSizeTextBoxName);
_canvasTextBoxItalicButton = (ToggleButton)GetTemplateChild(CanvasTextBoxItalicButtonName);
_canvasTextBoxBoldButton = (ToggleButton)GetTemplateChild(CanvasTextBoxBoldButtonName);
_drawingSurfaceRenderer = (InfiniteCanvasVirtualDrawingSurface)GetTemplateChild(DrawingSurfaceRendererName);
@ -301,7 +301,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
private void UnRegisterEvents()
{
_canvasTextBoxFontSizeTextBox.TextChanged -= CanvasTextBoxFontSizeTextBox_TextChanged;
_canvasComboBoxFontSizeTextBox.SelectionChanged -= CanvasComboBoxFontSizeTextBox_SelectionChanged;
_canvasTextBoxItalicButton.Click -= CanvasTextBoxItalicButton_Clicked;
_canvasTextBoxBoldButton.Click -= CanvasTextBoxBoldButton_Clicked;
_canvasTextBoxColorPicker.ColorChanged -= CanvasTextBoxColorPicker_ColorChanged;
@ -321,13 +321,14 @@ namespace CommunityToolkit.WinUI.UI.Controls
// Application.Current.LeavingBackground -= Current_LeavingBackground;
_drawingSurfaceRenderer.CommandExecuted -= DrawingSurfaceRenderer_CommandExecuted;
_canvasTextBoxFontSizeTextBox.PreviewKeyDown -= CanvasTextBoxFontSizeTextBox_PreviewKeyDown;
_canvasComboBoxFontSizeTextBox.PreviewKeyDown -= CanvasComboBoxFontSizeTextBox_PreviewKeyDown;
_canvasComboBoxFontSizeTextBox.TextSubmitted -= CanvasComboBoxFontSizeTextBox_TextSubmitted;
Loaded -= InfiniteCanvas_Loaded;
}
private void RegisterEvents()
{
_canvasTextBoxFontSizeTextBox.TextChanged += CanvasTextBoxFontSizeTextBox_TextChanged;
_canvasComboBoxFontSizeTextBox.SelectionChanged += CanvasComboBoxFontSizeTextBox_SelectionChanged;
_canvasTextBoxItalicButton.Click += CanvasTextBoxItalicButton_Clicked;
_canvasTextBoxBoldButton.Click += CanvasTextBoxBoldButton_Clicked;
_canvasTextBoxColorPicker.ColorChanged += CanvasTextBoxColorPicker_ColorChanged;
@ -347,7 +348,8 @@ namespace CommunityToolkit.WinUI.UI.Controls
// Application.Current.LeavingBackground += Current_LeavingBackground;
_drawingSurfaceRenderer.CommandExecuted += DrawingSurfaceRenderer_CommandExecuted;
_canvasTextBoxFontSizeTextBox.PreviewKeyDown += CanvasTextBoxFontSizeTextBox_PreviewKeyDown;
_canvasComboBoxFontSizeTextBox.PreviewKeyDown += CanvasComboBoxFontSizeTextBox_PreviewKeyDown;
_canvasComboBoxFontSizeTextBox.TextSubmitted += CanvasComboBoxFontSizeTextBox_TextSubmitted;
Loaded += InfiniteCanvas_Loaded;
}
@ -374,7 +376,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
SetCanvasWidthHeight();
_canvasTextBox.UpdateFontSize(TextFontSize);
SetFontSize(_textFontSize);
}
private void SetZoomFactor()

Просмотреть файл

@ -97,13 +97,32 @@
</ToggleButton.Content>
</ToggleButton>
<TextBox x:Name="CanvasTextBoxFontSizeTextBox"
Width="64"
Height="32"
InputScope="Number"
MaxLength="3"
Text="22"
ToolTipService.ToolTip="Font Size" />
<ComboBox x:Name="CanvasComboBoxFontSizeTextBox"
MinWidth="64"
Height="32"
SelectedIndex="9"
Margin="0,0,12,0"
VerticalAlignment="Center"
ToolTipService.ToolTip="Font Size"
IsEditable="True"
>
<ComboBoxItem Content="8" />
<ComboBoxItem Content="9" />
<ComboBoxItem Content="10" />
<ComboBoxItem Content="11" />
<ComboBoxItem Content="12" />
<ComboBoxItem Content="14" />
<ComboBoxItem Content="16" />
<ComboBoxItem Content="18" />
<ComboBoxItem Content="20" />
<ComboBoxItem Content="22" />
<ComboBoxItem Content="24" />
<ComboBoxItem Content="26" />
<ComboBoxItem Content="28" />
<ComboBoxItem Content="36" />
<ComboBoxItem Content="48" />
<ComboBoxItem Content="72" />
</ComboBox>
</StackPanel>
</StackPanel>

Просмотреть файл

@ -37,6 +37,8 @@ namespace UnitTests.UI.Controls
</controls:WrapPanel>
</Page>") as FrameworkElement;
treeRoot.UseLayoutRounding = false;
var expected = new (int u, int v, int w, int h)[]
{
(0, 0, 0, 0), // Collapsed
@ -94,6 +96,8 @@ namespace UnitTests.UI.Controls
</controls:WrapPanel>
</Page>") as FrameworkElement;
treeRoot.UseLayoutRounding = false;
var expected = new (int u, int v, int w, int h)[]
{
(0, 0, 150, 50),
@ -149,6 +153,8 @@ namespace UnitTests.UI.Controls
</controls:WrapPanel>
</Page>") as FrameworkElement;
treeRoot.UseLayoutRounding = false;
var expected = new (int u, int v, int w, int h)[]
{
(0, 0, 150, 50),

Просмотреть файл

@ -0,0 +1,15 @@
{
"solution": {
"path": "Windows Community Toolkit.sln",
"projects": [
"Microsoft.Toolkit.Diagnostics\\Microsoft.Toolkit.Diagnostics.csproj",
"Microsoft.Toolkit.HighPerformance\\Microsoft.Toolkit.HighPerformance.csproj",
"Microsoft.Toolkit.Mvvm\\Microsoft.Toolkit.Mvvm.csproj",
"Microsoft.Toolkit\\Microsoft.Toolkit.csproj",
"UnitTests\\UnitTests.HighPerformance.NetCore\\UnitTests.HighPerformance.NetCore.csproj",
"UnitTests\\UnitTests.HighPerformance.Shared\\UnitTests.HighPerformance.Shared.shproj",
"UnitTests\\UnitTests.NetCore\\UnitTests.NetCore.csproj",
"UnitTests\\UnitTests.Shared\\UnitTests.Shared.shproj"
]
}
}