From 869dd4ff9e4d2c71d4a87b4065fa713a125f5e9a Mon Sep 17 00:00:00 2001 From: null-val <59544401+null-val@users.noreply.github.com> Date: Sun, 29 Nov 2020 17:05:54 -0800 Subject: [PATCH 1/7] Added a theme listener, separate light/dark theme error styles, and property that returns the respective theme. resolves #3545 --- .../Controls/XamlCodeEditor.xaml.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs index d742974ab73..26516aa4cc3 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs @@ -21,6 +21,8 @@ public sealed partial class XamlCodeEditor : UserControl public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(XamlCodeEditor), new PropertyMetadata(string.Empty)); + private ThemeListener _themeListener = new ThemeListener(); + public XamlCodeEditor() { this.InitializeComponent(); @@ -40,7 +42,7 @@ public async void ReportError(XamlExceptionRange error) // Highlight Error Line XamlCodeRenderer.Decorations.Add(new IModelDeltaDecoration( range, - new IModelDecorationOptions() { IsWholeLine = true, ClassName = _errorStyle, HoverMessage = new string[] { error.Message }.ToMarkdownString() })); + new IModelDecorationOptions() { IsWholeLine = true, ClassName = ErrorStyle, HoverMessage = new string[] { error.Message }.ToMarkdownString() })); // Show Glyph Icon XamlCodeRenderer.Decorations.Add(new IModelDeltaDecoration( @@ -121,10 +123,13 @@ public string Text public DateTime TimeSampleEditedLast { get; private set; } = DateTime.MinValue; - private CssLineStyle _errorStyle = new CssLineStyle() + private CssLineStyle _errorStyle_Light = new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6)) }; + private CssLineStyle _errorStyle_Dark = new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0x6E, 0x00, 0x00)) }; + + private CssLineStyle ErrorStyle { - BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6)) - }; + get => _themeListener.CurrentTheme.Equals(ApplicationTheme.Light) ? _errorStyle_Light : _errorStyle_Dark; + } private CssGlyphStyle _errorIconStyle = new CssGlyphStyle() { From 31db7704e469a8ac21d6b7aba2ded277ce630617 Mon Sep 17 00:00:00 2001 From: null-val <59544401+null-val@users.noreply.github.com> Date: Sun, 29 Nov 2020 19:15:34 -0800 Subject: [PATCH 2/7] Consolidated code --- .../Controls/XamlCodeEditor.xaml.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs index 26516aa4cc3..7edd0fba455 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs @@ -123,12 +123,11 @@ public string Text public DateTime TimeSampleEditedLast { get; private set; } = DateTime.MinValue; - private CssLineStyle _errorStyle_Light = new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6)) }; - private CssLineStyle _errorStyle_Dark = new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0x6E, 0x00, 0x00)) }; - private CssLineStyle ErrorStyle { - get => _themeListener.CurrentTheme.Equals(ApplicationTheme.Light) ? _errorStyle_Light : _errorStyle_Dark; + get => _themeListener.CurrentTheme.Equals(ApplicationTheme.Light) ? + new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6)) } : + new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0x6E, 0x00, 0x00)) }; } private CssGlyphStyle _errorIconStyle = new CssGlyphStyle() From 92407a0fc3c15920536011c8c1831b8fec782bdb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 3 Dec 2020 20:18:36 +0100 Subject: [PATCH 3/7] Removed leftover DispatcherHelper usages --- .../DispatcherQueueHelperPage.xaml.cs | 3 +-- .../Shell.SamplePicker.cs | 3 ++- Microsoft.Toolkit.Uwp.SampleApp/Shell.Search.cs | 3 ++- Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml.cs | 3 ++- .../Extensions/AnimationExtensions.Light.cs | 6 +++--- ...ScrollViewerExtensions.MiddleClickScrolling.cs | 15 ++------------- .../XamlIslandsTest_Gaze.cs | 7 ++++--- 7 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DispatcherQueueHelper/DispatcherQueueHelperPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DispatcherQueueHelper/DispatcherQueueHelperPage.xaml.cs index fe61f6ea479..bde2d707c1f 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DispatcherQueueHelper/DispatcherQueueHelperPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DispatcherQueueHelper/DispatcherQueueHelperPage.xaml.cs @@ -3,10 +3,9 @@ // See the LICENSE file in the project root for more information. using System.Threading.Tasks; -using Microsoft.Toolkit.Uwp.Helpers; +using Microsoft.Toolkit.Uwp.Extensions; using Windows.System; using Windows.UI.Xaml; -using Microsoft.Toolkit.Uwp.Extensions; namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages { diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Shell.SamplePicker.cs b/Microsoft.Toolkit.Uwp.SampleApp/Shell.SamplePicker.cs index 80cc95787c6..b52099921b0 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Shell.SamplePicker.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/Shell.SamplePicker.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Numerics; using System.Threading.Tasks; +using Microsoft.Toolkit.Uwp.Extensions; using Microsoft.Toolkit.Uwp.Helpers; using Microsoft.Toolkit.Uwp.SampleApp.Pages; using Microsoft.Toolkit.Uwp.UI.Animations; @@ -147,7 +148,7 @@ private void NavView_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sende ShowSamplePicker(category.Samples, true); // Then Focus on Picker - DispatcherHelper.ExecuteOnUIThreadAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard)); + dispatcherQueue.EnqueueAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard)); } } else if (args.IsSettingsInvoked) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Shell.Search.cs b/Microsoft.Toolkit.Uwp.SampleApp/Shell.Search.cs index 34730cc0a74..0dd641d3f66 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Shell.Search.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/Shell.Search.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Linq; +using Microsoft.Toolkit.Uwp.Extensions; using Microsoft.Toolkit.Uwp.Helpers; using Microsoft.Toolkit.Uwp.UI.Extensions; using Windows.UI.Xaml; @@ -76,7 +77,7 @@ private void SearchBox_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEve if (e.Key == Windows.System.VirtualKey.Down && SamplePickerGrid.Visibility == Windows.UI.Xaml.Visibility.Visible) { // If we try and navigate down out of the textbox (and there's search results), go to the search results. - DispatcherHelper.ExecuteOnUIThreadAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard)); + dispatcherQueue.EnqueueAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard)); } } diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml.cs index d2f9ca0754b..44f63d1a251 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/Shell.xaml.cs @@ -7,7 +7,6 @@ using Microsoft.Toolkit.Uwp.SampleApp.Pages; using Microsoft.Toolkit.Uwp.UI.Extensions; using Windows.System; -using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; using Windows.UI.Xaml.Navigation; @@ -16,6 +15,8 @@ namespace Microsoft.Toolkit.Uwp.SampleApp { public sealed partial class Shell { + private readonly DispatcherQueue dispatcherQueue = DispatcherQueue.GetForCurrentThread(); + public static Shell Current { get; private set; } public Shell() diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs index 88573df78c9..c897d4cb206 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.Light.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.Effects; -using Microsoft.Toolkit.Uwp.Helpers; +using Microsoft.Toolkit.Uwp.Extensions; using Windows.UI; using Windows.UI.Composition; using Windows.UI.Composition.Effects; @@ -102,7 +102,7 @@ public static AnimationSet Light( var task = new AnimationTask(); task.AnimationSet = animationSet; - task.Task = DispatcherHelper.ExecuteOnUIThreadAsync( + task.Task = visual.DispatcherQueue.EnqueueAsync( () => { const string sceneName = "PointLightScene"; @@ -184,7 +184,7 @@ public static AnimationSet Light( } pointLights[visual] = pointLight; - }, Windows.UI.Core.CoreDispatcherPriority.Normal); + }); animationSet.AddAnimationThroughTask(task); return animationSet; diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/ScrollViewer/ScrollViewerExtensions.MiddleClickScrolling.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/ScrollViewer/ScrollViewerExtensions.MiddleClickScrolling.cs index 28bd87d9841..d603592c3a8 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/ScrollViewer/ScrollViewerExtensions.MiddleClickScrolling.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/ScrollViewer/ScrollViewerExtensions.MiddleClickScrolling.cs @@ -162,10 +162,7 @@ private static void Scroll(object state) offsetX = offsetX > _maxSpeed ? _maxSpeed : offsetX; offsetY = offsetY > _maxSpeed ? _maxSpeed : offsetY; - RunInUIThread(dispatcherQueue, () => - { - _scrollViewer?.ChangeView(_scrollViewer.HorizontalOffset + offsetX, _scrollViewer.VerticalOffset + offsetY, null, true); - }); + dispatcherQueue.EnqueueAsync(() => _scrollViewer?.ChangeView(_scrollViewer.HorizontalOffset + offsetX, _scrollViewer.VerticalOffset + offsetY, null, true)); } } @@ -326,10 +323,7 @@ private static void SetCursorType(DispatcherQueue dispatcherQueue, double offset if (_oldCursorID != cursorID) { - RunInUIThread(dispatcherQueue, () => - { - Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Custom, cursorID); - }); + dispatcherQueue.EnqueueAsync(() => Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Custom, cursorID)); _oldCursorID = cursorID; } @@ -366,10 +360,5 @@ private static bool IsCursorResourceAvailable() return isCursorAvailable; } - - private static async void RunInUIThread(DispatcherQueue dispatcherQueue, Action action) - { - await dispatcherQueue.EnqueueAsync(action, DispatcherQueuePriority.Normal); - } } } diff --git a/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_Gaze.cs b/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_Gaze.cs index f8133b8be71..ed2391b8336 100644 --- a/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_Gaze.cs +++ b/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_Gaze.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; +using Microsoft.Toolkit.Uwp.Extensions; using Microsoft.Toolkit.Uwp.Helpers; using Microsoft.Toolkit.Uwp.Input.GazeInteraction; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -21,7 +22,7 @@ public partial class XamlIslandsTest_Gaze [TestInitialize] public async Task Init() { - await App.Dispatcher.ExecuteOnUIThreadAsync(() => + await App.Dispatcher.EnqueueAsync(() => { var xamlItemsPanelTemplate = @" [TestCleanup] public async Task Cleanup() { - await App.Dispatcher.ExecuteOnUIThreadAsync(() => + await App.Dispatcher.EnqueueAsync(() => { GazeInput.SetInteraction(_grid, Interaction.Disabled); }); @@ -76,7 +77,7 @@ await App.Dispatcher.ExecuteOnUIThreadAsync(() => [Ignore] public async Task Gaze_DoesNotCrashOnIslands() { - await App.Dispatcher.ExecuteOnUIThreadAsync(async () => + await App.Dispatcher.EnqueueAsync(async () => { await Task.Delay(10000); From 8f3738d0bbb0543194d10bf6394c7e9e985d8b9a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 3 Dec 2020 20:25:11 +0100 Subject: [PATCH 4/7] Minor code tweaks --- .../Extensions/DispatcherQueueExtensions.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Microsoft.Toolkit.Uwp/Extensions/DispatcherQueueExtensions.cs b/Microsoft.Toolkit.Uwp/Extensions/DispatcherQueueExtensions.cs index 29bfbdad8ac..cb61cd2120e 100644 --- a/Microsoft.Toolkit.Uwp/Extensions/DispatcherQueueExtensions.cs +++ b/Microsoft.Toolkit.Uwp/Extensions/DispatcherQueueExtensions.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Windows.Foundation.Metadata; using Windows.System; @@ -67,7 +68,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Action function, Dispatc } })) { - taskCompletionSource.SetException(new InvalidOperationException("Failed to enqueue the operation")); + taskCompletionSource.SetException(GetEnqueueException("Failed to enqueue the operation")); } return taskCompletionSource.Task; @@ -116,7 +117,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func function, Dis } })) { - taskCompletionSource.SetException(new InvalidOperationException("Failed to enqueue the operation")); + taskCompletionSource.SetException(GetEnqueueException("Failed to enqueue the operation")); } return taskCompletionSource.Task; @@ -149,7 +150,7 @@ public static Task EnqueueAsync(this DispatcherQueue dispatcher, Func func return awaitableResult; } - return Task.FromException(new InvalidOperationException("The Task returned by function cannot be null.")); + return Task.FromException(GetEnqueueException("The Task returned by function cannot be null.")); } catch (Exception e) { @@ -173,7 +174,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func function, Dis } else { - taskCompletionSource.SetException(new InvalidOperationException("The Task returned by function cannot be null.")); + taskCompletionSource.SetException(GetEnqueueException("The Task returned by function cannot be null.")); } } catch (Exception e) @@ -182,7 +183,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func function, Dis } })) { - taskCompletionSource.SetException(new InvalidOperationException("Failed to enqueue the operation")); + taskCompletionSource.SetException(GetEnqueueException("Failed to enqueue the operation")); } return taskCompletionSource.Task; @@ -212,7 +213,7 @@ public static Task EnqueueAsync(this DispatcherQueue dispatcher, Func(new InvalidOperationException("The Task returned by function cannot be null.")); + return Task.FromException(GetEnqueueException("The Task returned by function cannot be null.")); } catch (Exception e) { @@ -236,7 +237,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func> functio } else { - taskCompletionSource.SetException(new InvalidOperationException("The Task returned by function cannot be null.")); + taskCompletionSource.SetException(GetEnqueueException("The Task returned by function cannot be null.")); } } catch (Exception e) @@ -245,7 +246,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func> functio } })) { - taskCompletionSource.SetException(new InvalidOperationException("Failed to enqueue the operation")); + taskCompletionSource.SetException(GetEnqueueException("Failed to enqueue the operation")); } return taskCompletionSource.Task; @@ -253,5 +254,16 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func> functio return TryEnqueueAsync(dispatcher, function, priority); } + + /// + /// Creates an to return when an enqueue operation fails. + /// + /// The message of the exception. + /// An with a specified message. + [MethodImpl(MethodImplOptions.NoInlining)] + private static InvalidOperationException GetEnqueueException(string message) + { + return new InvalidOperationException(message); + } } } From 02ba793bbeb78aa21121bcee9aa37cb1488e7d87 Mon Sep 17 00:00:00 2001 From: Arcadio Garcia Salvadores Date: Fri, 4 Dec 2020 11:36:11 -0800 Subject: [PATCH 5/7] Add unary operator --- .../Expressions/ExpressionFunctions.cs | 148 +++++++++--------- .../ExpressionNodes/ExpressionNode.cs | 9 ++ .../Expressions/OperationType.cs | 9 +- 3 files changed, 91 insertions(+), 75 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionFunctions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionFunctions.cs index 763a7a6fa05..b0f7b69b40d 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionFunctions.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionFunctions.cs @@ -1253,80 +1253,80 @@ public ExpressionNodeInfo(OperationType nodeOperationKind, string operationStrin /// private static readonly Dictionary _expressionNodeInfo = new Dictionary { - { ExpressionNodeType.ConstantValue, new ExpressionNodeInfo(OperationType.Constant, null) }, - { ExpressionNodeType.ConstantParameter, new ExpressionNodeInfo(OperationType.Constant, null) }, - { ExpressionNodeType.CurrentValueProperty, new ExpressionNodeInfo(OperationType.Reference, null) }, - { ExpressionNodeType.Reference, new ExpressionNodeInfo(OperationType.Reference, null) }, - { ExpressionNodeType.ReferenceProperty, new ExpressionNodeInfo(OperationType.Reference, null) }, - { ExpressionNodeType.StartingValueProperty, new ExpressionNodeInfo(OperationType.Reference, null) }, - { ExpressionNodeType.TargetReference, new ExpressionNodeInfo(OperationType.Reference, null) }, - { ExpressionNodeType.Conditional, new ExpressionNodeInfo(OperationType.Conditional, null) }, - { ExpressionNodeType.Swizzle, new ExpressionNodeInfo(OperationType.Swizzle, null) }, - { ExpressionNodeType.Add, new ExpressionNodeInfo(OperationType.Operator, "+") }, - { ExpressionNodeType.And, new ExpressionNodeInfo(OperationType.Operator, "&&") }, - { ExpressionNodeType.Divide, new ExpressionNodeInfo(OperationType.Operator, "/") }, - { ExpressionNodeType.Equals, new ExpressionNodeInfo(OperationType.Operator, "==") }, - { ExpressionNodeType.GreaterThan, new ExpressionNodeInfo(OperationType.Operator, ">") }, - { ExpressionNodeType.GreaterThanEquals, new ExpressionNodeInfo(OperationType.Operator, ">=") }, - { ExpressionNodeType.LessThan, new ExpressionNodeInfo(OperationType.Operator, "<") }, - { ExpressionNodeType.LessThanEquals, new ExpressionNodeInfo(OperationType.Operator, "<=") }, - { ExpressionNodeType.Multiply, new ExpressionNodeInfo(OperationType.Operator, "*") }, - { ExpressionNodeType.Not, new ExpressionNodeInfo(OperationType.Operator, "!") }, - { ExpressionNodeType.NotEquals, new ExpressionNodeInfo(OperationType.Operator, "!=") }, - { ExpressionNodeType.Or, new ExpressionNodeInfo(OperationType.Operator, "||") }, - { ExpressionNodeType.Subtract, new ExpressionNodeInfo(OperationType.Operator, "-") }, - { ExpressionNodeType.Absolute, new ExpressionNodeInfo(OperationType.Function, "abs") }, - { ExpressionNodeType.Acos, new ExpressionNodeInfo(OperationType.Function, "acos") }, - { ExpressionNodeType.Asin, new ExpressionNodeInfo(OperationType.Function, "asin") }, - { ExpressionNodeType.Atan, new ExpressionNodeInfo(OperationType.Function, "atan") }, - { ExpressionNodeType.Cos, new ExpressionNodeInfo(OperationType.Function, "cos") }, - { ExpressionNodeType.Ceil, new ExpressionNodeInfo(OperationType.Function, "ceil") }, - { ExpressionNodeType.Clamp, new ExpressionNodeInfo(OperationType.Function, "clamp") }, - { ExpressionNodeType.ColorHsl, new ExpressionNodeInfo(OperationType.Function, "colorhsl") }, - { ExpressionNodeType.ColorRgb, new ExpressionNodeInfo(OperationType.Function, "colorrgb") }, - { ExpressionNodeType.ColorLerp, new ExpressionNodeInfo(OperationType.Function, "colorlerp") }, - { ExpressionNodeType.ColorLerpHsl, new ExpressionNodeInfo(OperationType.Function, "colorhsllerp") }, - { ExpressionNodeType.ColorLerpRgb, new ExpressionNodeInfo(OperationType.Function, "colorrgblerp") }, - { ExpressionNodeType.Concatenate, new ExpressionNodeInfo(OperationType.Function, "concatenate") }, - { ExpressionNodeType.Distance, new ExpressionNodeInfo(OperationType.Function, "distance") }, - { ExpressionNodeType.DistanceSquared, new ExpressionNodeInfo(OperationType.Function, "distancesquared") }, - { ExpressionNodeType.Floor, new ExpressionNodeInfo(OperationType.Function, "floor") }, - { ExpressionNodeType.Inverse, new ExpressionNodeInfo(OperationType.Function, "inverse") }, - { ExpressionNodeType.Length, new ExpressionNodeInfo(OperationType.Function, "length") }, - { ExpressionNodeType.LengthSquared, new ExpressionNodeInfo(OperationType.Function, "lengthsquared") }, - { ExpressionNodeType.Lerp, new ExpressionNodeInfo(OperationType.Function, "lerp") }, - { ExpressionNodeType.Ln, new ExpressionNodeInfo(OperationType.Function, "ln") }, - { ExpressionNodeType.Log10, new ExpressionNodeInfo(OperationType.Function, "log10") }, - { ExpressionNodeType.Max, new ExpressionNodeInfo(OperationType.Function, "max") }, - { ExpressionNodeType.Matrix3x2FromRotation, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createrotation") }, - { ExpressionNodeType.Matrix3x2FromScale, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createscale") }, - { ExpressionNodeType.Matrix3x2FromSkew, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createskew") }, - { ExpressionNodeType.Matrix3x2FromTranslation, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createtranslation") }, - { ExpressionNodeType.Matrix3x2, new ExpressionNodeInfo(OperationType.Function, "matrix3x2") }, - { ExpressionNodeType.Matrix4x4FromAxisAngle, new ExpressionNodeInfo(OperationType.Function, "matrix4x4.createfromaxisangle") }, - { ExpressionNodeType.Matrix4x4FromScale, new ExpressionNodeInfo(OperationType.Function, "matrix4x4.createscale") }, - { ExpressionNodeType.Matrix4x4FromTranslation, new ExpressionNodeInfo(OperationType.Function, "matrix4x4.createtranslation") }, - { ExpressionNodeType.Matrix4x4, new ExpressionNodeInfo(OperationType.Function, "matrix4x4") }, - { ExpressionNodeType.Min, new ExpressionNodeInfo(OperationType.Function, "min") }, - { ExpressionNodeType.Modulus, new ExpressionNodeInfo(OperationType.Function, "mod") }, - { ExpressionNodeType.Negate, new ExpressionNodeInfo(OperationType.Function, "-") }, - { ExpressionNodeType.Normalize, new ExpressionNodeInfo(OperationType.Function, "normalize") }, - { ExpressionNodeType.Pow, new ExpressionNodeInfo(OperationType.Function, "pow") }, - { ExpressionNodeType.QuaternionFromAxisAngle, new ExpressionNodeInfo(OperationType.Function, "quaternion.createfromaxisangle") }, - { ExpressionNodeType.Quaternion, new ExpressionNodeInfo(OperationType.Function, "quaternion") }, - { ExpressionNodeType.Round, new ExpressionNodeInfo(OperationType.Function, "round") }, - { ExpressionNodeType.Scale, new ExpressionNodeInfo(OperationType.Function, "scale") }, - { ExpressionNodeType.Sin, new ExpressionNodeInfo(OperationType.Function, "sin") }, - { ExpressionNodeType.Slerp, new ExpressionNodeInfo(OperationType.Function, "slerp") }, - { ExpressionNodeType.Sqrt, new ExpressionNodeInfo(OperationType.Function, "sqrt") }, - { ExpressionNodeType.Square, new ExpressionNodeInfo(OperationType.Function, "square") }, - { ExpressionNodeType.Tan, new ExpressionNodeInfo(OperationType.Function, "tan") }, - { ExpressionNodeType.ToDegrees, new ExpressionNodeInfo(OperationType.Function, "todegrees") }, - { ExpressionNodeType.ToRadians, new ExpressionNodeInfo(OperationType.Function, "toradians") }, - { ExpressionNodeType.Transform, new ExpressionNodeInfo(OperationType.Function, "transform") }, - { ExpressionNodeType.Vector2, new ExpressionNodeInfo(OperationType.Function, "vector2") }, - { ExpressionNodeType.Vector3, new ExpressionNodeInfo(OperationType.Function, "vector3") }, - { ExpressionNodeType.Vector4, new ExpressionNodeInfo(OperationType.Function, "vector4") }, + { ExpressionNodeType.ConstantValue, new ExpressionNodeInfo(OperationType.Constant, null) }, + { ExpressionNodeType.ConstantParameter, new ExpressionNodeInfo(OperationType.Constant, null) }, + { ExpressionNodeType.CurrentValueProperty, new ExpressionNodeInfo(OperationType.Reference, null) }, + { ExpressionNodeType.Reference, new ExpressionNodeInfo(OperationType.Reference, null) }, + { ExpressionNodeType.ReferenceProperty, new ExpressionNodeInfo(OperationType.Reference, null) }, + { ExpressionNodeType.StartingValueProperty, new ExpressionNodeInfo(OperationType.Reference, null) }, + { ExpressionNodeType.TargetReference, new ExpressionNodeInfo(OperationType.Reference, null) }, + { ExpressionNodeType.Conditional, new ExpressionNodeInfo(OperationType.Conditional, null) }, + { ExpressionNodeType.Swizzle, new ExpressionNodeInfo(OperationType.Swizzle, null) }, + { ExpressionNodeType.Add, new ExpressionNodeInfo(OperationType.Operator, "+") }, + { ExpressionNodeType.And, new ExpressionNodeInfo(OperationType.Operator, "&&") }, + { ExpressionNodeType.Divide, new ExpressionNodeInfo(OperationType.Operator, "/") }, + { ExpressionNodeType.Equals, new ExpressionNodeInfo(OperationType.Operator, "==") }, + { ExpressionNodeType.GreaterThan, new ExpressionNodeInfo(OperationType.Operator, ">") }, + { ExpressionNodeType.GreaterThanEquals, new ExpressionNodeInfo(OperationType.Operator, ">=") }, + { ExpressionNodeType.LessThan, new ExpressionNodeInfo(OperationType.Operator, "<") }, + { ExpressionNodeType.LessThanEquals, new ExpressionNodeInfo(OperationType.Operator, "<=") }, + { ExpressionNodeType.Multiply, new ExpressionNodeInfo(OperationType.Operator, "*") }, + { ExpressionNodeType.Not, new ExpressionNodeInfo(OperationType.UnaryOperator, "!") }, + { ExpressionNodeType.NotEquals, new ExpressionNodeInfo(OperationType.Operator, "!=") }, + { ExpressionNodeType.Or, new ExpressionNodeInfo(OperationType.Operator, "||") }, + { ExpressionNodeType.Subtract, new ExpressionNodeInfo(OperationType.Operator, "-") }, + { ExpressionNodeType.Absolute, new ExpressionNodeInfo(OperationType.Function, "abs") }, + { ExpressionNodeType.Acos, new ExpressionNodeInfo(OperationType.Function, "acos") }, + { ExpressionNodeType.Asin, new ExpressionNodeInfo(OperationType.Function, "asin") }, + { ExpressionNodeType.Atan, new ExpressionNodeInfo(OperationType.Function, "atan") }, + { ExpressionNodeType.Cos, new ExpressionNodeInfo(OperationType.Function, "cos") }, + { ExpressionNodeType.Ceil, new ExpressionNodeInfo(OperationType.Function, "ceil") }, + { ExpressionNodeType.Clamp, new ExpressionNodeInfo(OperationType.Function, "clamp") }, + { ExpressionNodeType.ColorHsl, new ExpressionNodeInfo(OperationType.Function, "colorhsl") }, + { ExpressionNodeType.ColorRgb, new ExpressionNodeInfo(OperationType.Function, "colorrgb") }, + { ExpressionNodeType.ColorLerp, new ExpressionNodeInfo(OperationType.Function, "colorlerp") }, + { ExpressionNodeType.ColorLerpHsl, new ExpressionNodeInfo(OperationType.Function, "colorhsllerp") }, + { ExpressionNodeType.ColorLerpRgb, new ExpressionNodeInfo(OperationType.Function, "colorrgblerp") }, + { ExpressionNodeType.Concatenate, new ExpressionNodeInfo(OperationType.Function, "concatenate") }, + { ExpressionNodeType.Distance, new ExpressionNodeInfo(OperationType.Function, "distance") }, + { ExpressionNodeType.DistanceSquared, new ExpressionNodeInfo(OperationType.Function, "distancesquared") }, + { ExpressionNodeType.Floor, new ExpressionNodeInfo(OperationType.Function, "floor") }, + { ExpressionNodeType.Inverse, new ExpressionNodeInfo(OperationType.Function, "inverse") }, + { ExpressionNodeType.Length, new ExpressionNodeInfo(OperationType.Function, "length") }, + { ExpressionNodeType.LengthSquared, new ExpressionNodeInfo(OperationType.Function, "lengthsquared") }, + { ExpressionNodeType.Lerp, new ExpressionNodeInfo(OperationType.Function, "lerp") }, + { ExpressionNodeType.Ln, new ExpressionNodeInfo(OperationType.Function, "ln") }, + { ExpressionNodeType.Log10, new ExpressionNodeInfo(OperationType.Function, "log10") }, + { ExpressionNodeType.Max, new ExpressionNodeInfo(OperationType.Function, "max") }, + { ExpressionNodeType.Matrix3x2FromRotation, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createrotation") }, + { ExpressionNodeType.Matrix3x2FromScale, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createscale") }, + { ExpressionNodeType.Matrix3x2FromSkew, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createskew") }, + { ExpressionNodeType.Matrix3x2FromTranslation, new ExpressionNodeInfo(OperationType.Function, "matrix3x2.createtranslation") }, + { ExpressionNodeType.Matrix3x2, new ExpressionNodeInfo(OperationType.Function, "matrix3x2") }, + { ExpressionNodeType.Matrix4x4FromAxisAngle, new ExpressionNodeInfo(OperationType.Function, "matrix4x4.createfromaxisangle") }, + { ExpressionNodeType.Matrix4x4FromScale, new ExpressionNodeInfo(OperationType.Function, "matrix4x4.createscale") }, + { ExpressionNodeType.Matrix4x4FromTranslation, new ExpressionNodeInfo(OperationType.Function, "matrix4x4.createtranslation") }, + { ExpressionNodeType.Matrix4x4, new ExpressionNodeInfo(OperationType.Function, "matrix4x4") }, + { ExpressionNodeType.Min, new ExpressionNodeInfo(OperationType.Function, "min") }, + { ExpressionNodeType.Modulus, new ExpressionNodeInfo(OperationType.Function, "mod") }, + { ExpressionNodeType.Negate, new ExpressionNodeInfo(OperationType.Function, "-") }, + { ExpressionNodeType.Normalize, new ExpressionNodeInfo(OperationType.Function, "normalize") }, + { ExpressionNodeType.Pow, new ExpressionNodeInfo(OperationType.Function, "pow") }, + { ExpressionNodeType.QuaternionFromAxisAngle, new ExpressionNodeInfo(OperationType.Function, "quaternion.createfromaxisangle") }, + { ExpressionNodeType.Quaternion, new ExpressionNodeInfo(OperationType.Function, "quaternion") }, + { ExpressionNodeType.Round, new ExpressionNodeInfo(OperationType.Function, "round") }, + { ExpressionNodeType.Scale, new ExpressionNodeInfo(OperationType.Function, "scale") }, + { ExpressionNodeType.Sin, new ExpressionNodeInfo(OperationType.Function, "sin") }, + { ExpressionNodeType.Slerp, new ExpressionNodeInfo(OperationType.Function, "slerp") }, + { ExpressionNodeType.Sqrt, new ExpressionNodeInfo(OperationType.Function, "sqrt") }, + { ExpressionNodeType.Square, new ExpressionNodeInfo(OperationType.Function, "square") }, + { ExpressionNodeType.Tan, new ExpressionNodeInfo(OperationType.Function, "tan") }, + { ExpressionNodeType.ToDegrees, new ExpressionNodeInfo(OperationType.Function, "todegrees") }, + { ExpressionNodeType.ToRadians, new ExpressionNodeInfo(OperationType.Function, "toradians") }, + { ExpressionNodeType.Transform, new ExpressionNodeInfo(OperationType.Function, "transform") }, + { ExpressionNodeType.Vector2, new ExpressionNodeInfo(OperationType.Function, "vector2") }, + { ExpressionNodeType.Vector3, new ExpressionNodeInfo(OperationType.Function, "vector3") }, + { ExpressionNodeType.Vector4, new ExpressionNodeInfo(OperationType.Function, "vector4") }, }; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs index 48464ef9e4c..e578a450adf 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs @@ -502,6 +502,15 @@ private string ToExpressionStringInternal() ret = $"({Children[0].ToExpressionStringInternal()} {GetOperationString()} {Children[1].ToExpressionStringInternal()})"; break; + case OperationType.UnaryOperator: + if (Children.Count != 1) + { + throw new Exception("Can't have an unary operator that doesn't have exactly one params"); + } + + ret = $"( {GetOperationString()} {Children[0].ToExpressionStringInternal()} )"; + break; + case OperationType.Constant: if (Children.Count == 0) { diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs index fae5e51c838..f5b0ed9a58d 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs @@ -15,10 +15,17 @@ internal enum OperationType Function, /// - /// The operator + /// The operator (takes two operands) /// Operator, + + /// + /// The operator that only takes one operand + /// + UnaryOperator, + + /// /// The constant /// From a29dca636fd0e839edb2646c198a8af45eec8c65 Mon Sep 17 00:00:00 2001 From: Arcadio Garcia Salvadores Date: Fri, 4 Dec 2020 11:38:01 -0800 Subject: [PATCH 6/7] Cleanup --- .../Expressions/OperationType.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs index f5b0ed9a58d..6708645909f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/OperationType.cs @@ -19,13 +19,11 @@ internal enum OperationType /// Operator, - /// /// The operator that only takes one operand /// UnaryOperator, - /// /// The constant /// From 033cd45fe2a4cb24bf165b08f35abc64744b0bbe Mon Sep 17 00:00:00 2001 From: null-val <59544401+null-val@users.noreply.github.com> Date: Fri, 4 Dec 2020 13:33:57 -0800 Subject: [PATCH 7/7] Updated dark theme color to #660000 --- .../Controls/XamlCodeEditor.xaml.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs index 7edd0fba455..2060cd25bb4 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs @@ -125,9 +125,9 @@ public string Text private CssLineStyle ErrorStyle { - get => _themeListener.CurrentTheme.Equals(ApplicationTheme.Light) ? - new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6)) } : - new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0x6E, 0x00, 0x00)) }; + get => _themeListener.CurrentTheme.Equals(ApplicationTheme.Light) ? + new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6)) } : + new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0x66, 0x00, 0x00)) }; } private CssGlyphStyle _errorIconStyle = new CssGlyphStyle()