Skip to content

Commit fedf3f9

Browse files
committed
Merge branch 'master' into winui
2 parents 2216723 + 385e4fb commit fedf3f9

File tree

9 files changed

+117
-63
lines changed

9 files changed

+117
-63
lines changed

CommunityToolkit.Mvvm/Messaging/WeakReferenceMessenger.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
using System.Runtime.CompilerServices;
1010
using CommunityToolkit.Mvvm.Messaging.Internals;
1111
using Microsoft.Collections.Extensions;
12-
#if NETSTANDARD2_1
13-
using RecipientsTable = System.Runtime.CompilerServices.ConditionalWeakTable<object, Microsoft.Collections.Extensions.IDictionarySlim>;
14-
#else
12+
#if NETSTANDARD2_0
1513
using RecipientsTable = CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger.ConditionalWeakTable<object, Microsoft.Collections.Extensions.IDictionarySlim>;
14+
#else
15+
using RecipientsTable = System.Runtime.CompilerServices.ConditionalWeakTable<object, Microsoft.Collections.Extensions.IDictionarySlim>;
1616
#endif
1717

1818
namespace CommunityToolkit.Mvvm.Messaging
@@ -288,7 +288,7 @@ public void Reset()
288288
}
289289
}
290290

291-
#if !NETSTANDARD2_1
291+
#if NETSTANDARD2_0
292292
/// <summary>
293293
/// A wrapper for <see cref="System.Runtime.CompilerServices.ConditionalWeakTable{TKey,TValue}"/>
294294
/// that backports the enumerable support to .NET Standard 2.0 through an auxiliary list.
@@ -470,7 +470,7 @@ private ref struct ArrayPoolBufferWriter<T>
470470
[MethodImpl(MethodImplOptions.AggressiveInlining)]
471471
public static ArrayPoolBufferWriter<T> Create()
472472
{
473-
return new ArrayPoolBufferWriter<T> { array = ArrayPool<T>.Shared.Rent(DefaultInitialBufferSize) };
473+
return new() { array = ArrayPool<T>.Shared.Rent(DefaultInitialBufferSize) };
474474
}
475475

476476
/// <summary>

CommunityToolkit.WinUI.SampleApp/SamplePages/Mouse/MouseCursorPage.bind

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Margin="50,100,20,20"
99
HorizontalAlignment="Left"
1010
VerticalAlignment="Top"
11-
ui:Mouse.Cursor="UniversalNo"
11+
ui:FrameworkElementExtensions.Cursor="UniversalNo"
1212
Background="DeepSkyBlue">
1313
<TextBlock Margin="4"
1414
HorizontalAlignment="Center"
@@ -21,7 +21,7 @@
2121
Margin="20"
2222
HorizontalAlignment="Left"
2323
VerticalAlignment="Top"
24-
ui:Mouse.Cursor="Wait"
24+
ui:FrameworkElementExtensions.Cursor="Wait"
2525
Background="Orange">
2626
<TextBlock Margin="4"
2727
HorizontalAlignment="Center"
@@ -37,7 +37,7 @@
3737
<Button Margin="20,290,20,20"
3838
HorizontalAlignment="Left"
3939
VerticalAlignment="Top"
40-
ui:Mouse.Cursor="Hand"
40+
ui:FrameworkElementExtensions.Cursor="Hand"
4141
Content="Button with Hand cursor, just like on web" />
4242
</Grid>
43-
</Page>
43+
</Page>

CommunityToolkit.WinUI.UI.Controls.Media/InfiniteCanvas/Commands/InfiniteCanvasCreateTextBoxCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class InfiniteCanvasCreateTextBoxCommand : IInfiniteCanvasCommand
1212
private readonly List<IDrawable> _drawableList;
1313
private readonly TextDrawable _drawable;
1414

15-
public InfiniteCanvasCreateTextBoxCommand(List<IDrawable> drawableList, double x, double y, double width, double height, int textFontSize, string text, Color color, bool isBold, bool isItalic)
15+
public InfiniteCanvasCreateTextBoxCommand(List<IDrawable> drawableList, double x, double y, double width, double height, float textFontSize, string text, Color color, bool isBold, bool isItalic)
1616
{
1717
_drawable = new TextDrawable(
1818
x,

CommunityToolkit.WinUI.UI.Controls.Media/InfiniteCanvas/Controls/InfiniteCanvasVirtualDrawingSurface.Commands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal void ExecuteUpdateTextBoxFontSize(float newValue)
7979
ExecuteCommand(command);
8080
}
8181

82-
internal void ExecuteCreateTextBox(double x, double y, double width, double height, int textFontSize, string text, Color color, bool isBold, bool isItalic)
82+
internal void ExecuteCreateTextBox(double x, double y, double width, double height, float textFontSize, string text, Color color, bool isBold, bool isItalic)
8383
{
8484
var command = new InfiniteCanvasCreateTextBoxCommand(_drawableList, x, y, width, height, textFontSize, text, color, isBold, isItalic);
8585
ExecuteCommand(command);

CommunityToolkit.WinUI.UI.Controls.Media/InfiniteCanvas/InfiniteCanvas.TextBox.cs

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,20 @@ public partial class InfiniteCanvas
2828
"Right",
2929
"Up",
3030
"Left",
31-
"Down"
31+
"Down",
32+
"Enter"
3233
};
3334

3435
private Point _lastInputPoint;
3536

3637
private TextDrawable SelectedTextDrawable => _drawingSurfaceRenderer.GetSelectedTextDrawable();
3738

38-
private int _lastValidTextFontSizeValue = DefaultFontValue;
39+
private float _textFontSize = DefaultFontValue;
3940

40-
private int TextFontSize
41+
private void SetFontSize(float newSize)
4142
{
42-
get
43-
{
44-
if (!string.IsNullOrWhiteSpace(_canvasTextBoxFontSizeTextBox.Text) &&
45-
Regex.IsMatch(_canvasTextBoxFontSizeTextBox.Text, "^[0-9]*$"))
46-
{
47-
var fontSize = int.Parse(_canvasTextBoxFontSizeTextBox.Text);
48-
_lastValidTextFontSizeValue = fontSize;
49-
}
50-
51-
return _lastValidTextFontSizeValue;
52-
}
43+
_textFontSize = newSize;
44+
_canvasTextBox.UpdateFontSize(newSize);
5345
}
5446

5547
private void InkScrollViewer_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
@@ -93,13 +85,34 @@ private void CanvasTextBoxItalicButton_Clicked(object sender, RoutedEventArgs e)
9385
}
9486
}
9587

96-
private void CanvasTextBoxFontSizeTextBox_TextChanged(object sender, TextChangedEventArgs e)
88+
private void CanvasComboBoxFontSizeTextBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
9789
{
98-
_canvasTextBox.UpdateFontSize(TextFontSize);
99-
if (SelectedTextDrawable != null)
90+
if (sender is ComboBox s
91+
&& s.SelectedItem is ComboBoxItem selectedItem
92+
&& selectedItem.Content is string selectedText
93+
&& float.TryParse(selectedText, out var sizeNumb))
10094
{
101-
_drawingSurfaceRenderer.ExecuteUpdateTextBoxFontSize(TextFontSize);
102-
ReDrawCanvas();
95+
SetFontSize(sizeNumb);
96+
97+
if (SelectedTextDrawable != null)
98+
{
99+
_drawingSurfaceRenderer.ExecuteUpdateTextBoxFontSize(sizeNumb);
100+
ReDrawCanvas();
101+
}
102+
}
103+
}
104+
105+
private void CanvasComboBoxFontSizeTextBox_TextSubmitted(ComboBox sender, ComboBoxTextSubmittedEventArgs args)
106+
{
107+
if (float.TryParse(args.Text, out var size))
108+
{
109+
SetFontSize(size);
110+
111+
if (SelectedTextDrawable != null)
112+
{
113+
_drawingSurfaceRenderer.ExecuteUpdateTextBoxFontSize(size);
114+
ReDrawCanvas();
115+
}
103116
}
104117
}
105118

@@ -147,20 +160,22 @@ private void CanvasTextBox_TextChanged(object sender, string text)
147160
ReDrawCanvas();
148161
return;
149162
}
163+
else
164+
{
165+
_drawingSurfaceRenderer.ExecuteCreateTextBox(
166+
_lastInputPoint.X,
167+
_lastInputPoint.Y,
168+
_canvasTextBox.GetEditZoneWidth(),
169+
_canvasTextBox.GetEditZoneHeight(),
170+
_textFontSize,
171+
text,
172+
_canvasTextBoxColorPicker.Color,
173+
_canvasTextBoxBoldButton.IsChecked ?? false,
174+
_canvasTextBoxItalicButton.IsChecked ?? false);
150175

151-
_drawingSurfaceRenderer.ExecuteCreateTextBox(
152-
_lastInputPoint.X,
153-
_lastInputPoint.Y,
154-
_canvasTextBox.GetEditZoneWidth(),
155-
_canvasTextBox.GetEditZoneHeight(),
156-
TextFontSize,
157-
text,
158-
_canvasTextBoxColorPicker.Color,
159-
_canvasTextBoxBoldButton.IsChecked ?? false,
160-
_canvasTextBoxItalicButton.IsChecked ?? false);
161-
162-
ReDrawCanvas();
163-
_drawingSurfaceRenderer.UpdateSelectedTextDrawable();
176+
ReDrawCanvas();
177+
_drawingSurfaceRenderer.UpdateSelectedTextDrawable();
178+
}
164179
}
165180

166181
private void InkScrollViewer_PointerPressed(object sender, PointerRoutedEventArgs e)
@@ -180,20 +195,17 @@ private void InkScrollViewer_PointerPressed(object sender, PointerRoutedEventArg
180195
181196
Canvas.SetLeft(_canvasTextBox, SelectedTextDrawable.Bounds.X);
182197
Canvas.SetTop(_canvasTextBox, SelectedTextDrawable.Bounds.Y);
183-
_canvasTextBox.UpdateFontSize(SelectedTextDrawable.FontSize);
184198
_canvasTextBox.UpdateFontStyle(SelectedTextDrawable.IsItalic);
185199
_canvasTextBox.UpdateFontWeight(SelectedTextDrawable.IsBold);
186200
187201
// Updating toolbar
188202
_canvasTextBoxColorPicker.Color = SelectedTextDrawable.TextColor;
189-
_canvasTextBoxFontSizeTextBox.Text = SelectedTextDrawable.FontSize.ToString();
190203
_canvasTextBoxBoldButton.IsChecked = SelectedTextDrawable.IsBold;
191204
_canvasTextBoxItalicButton.IsChecked = SelectedTextDrawable.IsItalic;
192205
193206
return;
194207
}
195208
196-
_canvasTextBox.UpdateFontSize(TextFontSize);
197209
_canvasTextBox.UpdateFontStyle(_canvasTextBoxItalicButton.IsChecked ?? false);
198210
_canvasTextBox.UpdateFontWeight(_canvasTextBoxBoldButton.IsChecked ?? false);
199211
@@ -212,7 +224,7 @@ private void ClearTextBoxValue()
212224
_canvasTextBox.Clear();
213225
}
214226

215-
private void CanvasTextBoxFontSizeTextBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
227+
private void CanvasComboBoxFontSizeTextBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
216228
{
217229
if (_allowedCommands.Contains(e.Key.ToString()))
218230
{

CommunityToolkit.WinUI.UI.Controls.Media/InfiniteCanvas/InfiniteCanvas.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace CommunityToolkit.WinUI.UI.Controls
2121
/// </summary>
2222
[TemplatePart(Name = CanvasTextBoxToolsName, Type = typeof(StackPanel))]
2323
[TemplatePart(Name = CanvasTextBoxColorPickerName, Type = typeof(Microsoft.UI.Xaml.Controls.ColorPicker))]
24-
[TemplatePart(Name = CanvasTextBoxFontSizeTextBoxName, Type = typeof(TextBox))]
24+
[TemplatePart(Name = CanvasComboBoxFontSizeTextBoxName, Type = typeof(TextBox))]
2525
[TemplatePart(Name = CanvasTextBoxItalicButtonName, Type = typeof(ToggleButton))]
2626
[TemplatePart(Name = CanvasTextBoxBoldButtonName, Type = typeof(ToggleButton))]
2727
[TemplatePart(Name = DrawingSurfaceRendererName, Type = typeof(InfiniteCanvasVirtualDrawingSurface))]
@@ -47,7 +47,7 @@ public partial class InfiniteCanvas : Control
4747

4848
private const string CanvasTextBoxToolsName = "CanvasTextBoxTools";
4949
private const string CanvasTextBoxColorPickerName = "CanvasTextBoxColorPicker";
50-
private const string CanvasTextBoxFontSizeTextBoxName = "CanvasTextBoxFontSizeTextBox";
50+
private const string CanvasComboBoxFontSizeTextBoxName = "CanvasComboBoxFontSizeTextBox";
5151
private const string CanvasTextBoxItalicButtonName = "CanvasTextBoxItalicButton";
5252
private const string CanvasTextBoxBoldButtonName = "CanvasTextBoxBoldButton";
5353
private const string DrawingSurfaceRendererName = "DrawingSurfaceRenderer";
@@ -75,7 +75,7 @@ public partial class InfiniteCanvas : Control
7575
private StackPanel _canvasTextBoxTools;
7676
private Microsoft.UI.Xaml.Controls.ColorPicker _canvasTextBoxColorPicker;
7777

78-
private TextBox _canvasTextBoxFontSizeTextBox;
78+
private ComboBox _canvasComboBoxFontSizeTextBox;
7979
private ToggleButton _canvasTextBoxItalicButton;
8080
private ToggleButton _canvasTextBoxBoldButton;
8181
private Button _undoButton;
@@ -248,7 +248,7 @@ protected override void OnApplyTemplate()
248248
{
249249
_canvasTextBoxTools = (StackPanel)GetTemplateChild(CanvasTextBoxToolsName);
250250
this._canvasTextBoxColorPicker = (Microsoft.UI.Xaml.Controls.ColorPicker)GetTemplateChild(CanvasTextBoxColorPickerName);
251-
_canvasTextBoxFontSizeTextBox = (TextBox)GetTemplateChild(CanvasTextBoxFontSizeTextBoxName);
251+
_canvasComboBoxFontSizeTextBox = (ComboBox)GetTemplateChild(CanvasComboBoxFontSizeTextBoxName);
252252
_canvasTextBoxItalicButton = (ToggleButton)GetTemplateChild(CanvasTextBoxItalicButtonName);
253253
_canvasTextBoxBoldButton = (ToggleButton)GetTemplateChild(CanvasTextBoxBoldButtonName);
254254
_drawingSurfaceRenderer = (InfiniteCanvasVirtualDrawingSurface)GetTemplateChild(DrawingSurfaceRendererName);
@@ -301,7 +301,7 @@ protected override void OnApplyTemplate()
301301

302302
private void UnRegisterEvents()
303303
{
304-
_canvasTextBoxFontSizeTextBox.TextChanged -= CanvasTextBoxFontSizeTextBox_TextChanged;
304+
_canvasComboBoxFontSizeTextBox.SelectionChanged -= CanvasComboBoxFontSizeTextBox_SelectionChanged;
305305
_canvasTextBoxItalicButton.Click -= CanvasTextBoxItalicButton_Clicked;
306306
_canvasTextBoxBoldButton.Click -= CanvasTextBoxBoldButton_Clicked;
307307
_canvasTextBoxColorPicker.ColorChanged -= CanvasTextBoxColorPicker_ColorChanged;
@@ -321,13 +321,14 @@ private void UnRegisterEvents()
321321

322322
// Application.Current.LeavingBackground -= Current_LeavingBackground;
323323
_drawingSurfaceRenderer.CommandExecuted -= DrawingSurfaceRenderer_CommandExecuted;
324-
_canvasTextBoxFontSizeTextBox.PreviewKeyDown -= CanvasTextBoxFontSizeTextBox_PreviewKeyDown;
324+
_canvasComboBoxFontSizeTextBox.PreviewKeyDown -= CanvasComboBoxFontSizeTextBox_PreviewKeyDown;
325+
_canvasComboBoxFontSizeTextBox.TextSubmitted -= CanvasComboBoxFontSizeTextBox_TextSubmitted;
325326
Loaded -= InfiniteCanvas_Loaded;
326327
}
327328

328329
private void RegisterEvents()
329330
{
330-
_canvasTextBoxFontSizeTextBox.TextChanged += CanvasTextBoxFontSizeTextBox_TextChanged;
331+
_canvasComboBoxFontSizeTextBox.SelectionChanged += CanvasComboBoxFontSizeTextBox_SelectionChanged;
331332
_canvasTextBoxItalicButton.Click += CanvasTextBoxItalicButton_Clicked;
332333
_canvasTextBoxBoldButton.Click += CanvasTextBoxBoldButton_Clicked;
333334
_canvasTextBoxColorPicker.ColorChanged += CanvasTextBoxColorPicker_ColorChanged;
@@ -347,7 +348,8 @@ private void RegisterEvents()
347348

348349
// Application.Current.LeavingBackground += Current_LeavingBackground;
349350
_drawingSurfaceRenderer.CommandExecuted += DrawingSurfaceRenderer_CommandExecuted;
350-
_canvasTextBoxFontSizeTextBox.PreviewKeyDown += CanvasTextBoxFontSizeTextBox_PreviewKeyDown;
351+
_canvasComboBoxFontSizeTextBox.PreviewKeyDown += CanvasComboBoxFontSizeTextBox_PreviewKeyDown;
352+
_canvasComboBoxFontSizeTextBox.TextSubmitted += CanvasComboBoxFontSizeTextBox_TextSubmitted;
351353
Loaded += InfiniteCanvas_Loaded;
352354
}
353355

@@ -374,7 +376,7 @@ private void ConfigureControls()
374376

375377
SetCanvasWidthHeight();
376378

377-
_canvasTextBox.UpdateFontSize(TextFontSize);
379+
SetFontSize(_textFontSize);
378380
}
379381

380382
private void SetZoomFactor()

CommunityToolkit.WinUI.UI.Controls.Media/InfiniteCanvas/InfiniteCanvas.xaml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,32 @@
9797
</ToggleButton.Content>
9898
</ToggleButton>
9999

100-
<TextBox x:Name="CanvasTextBoxFontSizeTextBox"
101-
Width="64"
102-
Height="32"
103-
InputScope="Number"
104-
MaxLength="3"
105-
Text="22"
106-
ToolTipService.ToolTip="Font Size" />
100+
<ComboBox x:Name="CanvasComboBoxFontSizeTextBox"
101+
MinWidth="64"
102+
Height="32"
103+
SelectedIndex="9"
104+
Margin="0,0,12,0"
105+
VerticalAlignment="Center"
106+
ToolTipService.ToolTip="Font Size"
107+
IsEditable="True"
108+
>
109+
<ComboBoxItem Content="8" />
110+
<ComboBoxItem Content="9" />
111+
<ComboBoxItem Content="10" />
112+
<ComboBoxItem Content="11" />
113+
<ComboBoxItem Content="12" />
114+
<ComboBoxItem Content="14" />
115+
<ComboBoxItem Content="16" />
116+
<ComboBoxItem Content="18" />
117+
<ComboBoxItem Content="20" />
118+
<ComboBoxItem Content="22" />
119+
<ComboBoxItem Content="24" />
120+
<ComboBoxItem Content="26" />
121+
<ComboBoxItem Content="28" />
122+
<ComboBoxItem Content="36" />
123+
<ComboBoxItem Content="48" />
124+
<ComboBoxItem Content="72" />
125+
</ComboBox>
107126

108127
</StackPanel>
109128
</StackPanel>

UnitTests/UnitTests.UWP/UI/Controls/Test_WrapPanel_Visibility.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
3737
</controls:WrapPanel>
3838
</Page>") as FrameworkElement;
3939

40+
treeRoot.UseLayoutRounding = false;
41+
4042
var expected = new (int u, int v, int w, int h)[]
4143
{
4244
(0, 0, 0, 0), // Collapsed
@@ -94,6 +96,8 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
9496
</controls:WrapPanel>
9597
</Page>") as FrameworkElement;
9698

99+
treeRoot.UseLayoutRounding = false;
100+
97101
var expected = new (int u, int v, int w, int h)[]
98102
{
99103
(0, 0, 150, 50),
@@ -149,6 +153,8 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
149153
</controls:WrapPanel>
150154
</Page>") as FrameworkElement;
151155

156+
treeRoot.UseLayoutRounding = false;
157+
152158
var expected = new (int u, int v, int w, int h)[]
153159
{
154160
(0, 0, 150, 50),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"solution": {
3+
"path": "Windows Community Toolkit.sln",
4+
"projects": [
5+
"Microsoft.Toolkit.Diagnostics\\Microsoft.Toolkit.Diagnostics.csproj",
6+
"Microsoft.Toolkit.HighPerformance\\Microsoft.Toolkit.HighPerformance.csproj",
7+
"Microsoft.Toolkit.Mvvm\\Microsoft.Toolkit.Mvvm.csproj",
8+
"Microsoft.Toolkit\\Microsoft.Toolkit.csproj",
9+
"UnitTests\\UnitTests.HighPerformance.NetCore\\UnitTests.HighPerformance.NetCore.csproj",
10+
"UnitTests\\UnitTests.HighPerformance.Shared\\UnitTests.HighPerformance.Shared.shproj",
11+
"UnitTests\\UnitTests.NetCore\\UnitTests.NetCore.csproj",
12+
"UnitTests\\UnitTests.Shared\\UnitTests.Shared.shproj"
13+
]
14+
}
15+
}

0 commit comments

Comments
 (0)