Browse Source

Merge branch 'master' into validate-fix

mstr2 6 years ago
parent
commit
449e9f2353

+ 2 - 3
src/Avalonia.Controls/AppBuilderBase.cs

@@ -125,9 +125,8 @@ namespace Avalonia.Controls
             });
             
             // Copy-pasted because we can't call extension methods due to generic constraints
-            var lifetime = new ClassicDesktopStyleApplicationLifetime(Instance) {ShutdownMode = ShutdownMode.OnMainWindowClose};
-            Instance.ApplicationLifetime = lifetime;
-            SetupWithoutStarting();
+            var lifetime = new ClassicDesktopStyleApplicationLifetime() {ShutdownMode = ShutdownMode.OnMainWindowClose};
+            SetupWithLifetime(lifetime);
             lifetime.Start(Array.Empty<string>());
         }
 

+ 4 - 5
src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs

@@ -5,12 +5,12 @@ using System.Threading;
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Interactivity;
+using Avalonia.Threading;
 
 namespace Avalonia.Controls.ApplicationLifetimes
 {
     public class ClassicDesktopStyleApplicationLifetime : IClassicDesktopStyleApplicationLifetime, IDisposable
     {
-        private readonly Application _app;
         private int _exitCode;
         private CancellationTokenSource _cts;
         private bool _isShuttingDown;
@@ -34,12 +34,11 @@ namespace Avalonia.Controls.ApplicationLifetimes
             _activeLifetime?._windows.Add((Window)sender);
         }
 
-        public ClassicDesktopStyleApplicationLifetime(Application app)
+        public ClassicDesktopStyleApplicationLifetime()
         {
             if (_activeLifetime != null)
                 throw new InvalidOperationException(
                     "Can not have multiple active ClassicDesktopStyleApplicationLifetime instances and the previously created one was not disposed");
-            _app = app;
             _activeLifetime = this;
         }
         
@@ -103,7 +102,7 @@ namespace Avalonia.Controls.ApplicationLifetimes
             Startup?.Invoke(this, new ControlledApplicationLifetimeStartupEventArgs(args));
             _cts = new CancellationTokenSource();
             MainWindow?.Show();
-            _app.Run(_cts.Token);
+            Dispatcher.UIThread.MainLoop(_cts.Token);
             Environment.ExitCode = _exitCode;
             return _exitCode;
         }
@@ -124,7 +123,7 @@ namespace Avalonia
             this T builder, string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose)
             where T : AppBuilderBase<T>, new()
         {
-            var lifetime = new ClassicDesktopStyleApplicationLifetime(builder.Instance) {ShutdownMode = shutdownMode};
+            var lifetime = new ClassicDesktopStyleApplicationLifetime() {ShutdownMode = shutdownMode};
             builder.SetupWithLifetime(lifetime);
             return lifetime.Start(args);
         }

+ 3 - 1
src/Avalonia.Controls/ColumnDefinition.cs

@@ -31,7 +31,9 @@ namespace Avalonia.Controls
         /// </summary>
         static ColumnDefinition()
         {
-            AffectsParentMeasure(WidthProperty, MinWidthProperty, MaxWidthProperty);
+            AffectsParentMeasure(MinWidthProperty, MaxWidthProperty);
+
+            WidthProperty.Changed.AddClassHandler<DefinitionBase>(OnUserSizePropertyChanged);
         }
 
         /// <summary>

+ 30 - 3
src/Avalonia.Controls/DefinitionBase.cs

@@ -7,9 +7,6 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics;
-
-using Avalonia;
-using Avalonia.Collections;
 using Avalonia.Utilities;
 
 namespace Avalonia.Controls
@@ -118,6 +115,36 @@ namespace Avalonia.Controls
             }
         }
 
+        /// <remarks>
+        /// Notifies parent <see cref="Grid"/> or size scope that definition size has been changed.
+        /// </remarks>
+        internal static void OnUserSizePropertyChanged(DefinitionBase definition, AvaloniaPropertyChangedEventArgs e)
+        {
+            if (definition.Parent == null)
+            {
+                return;
+            }
+
+            if (definition._sharedState != null)
+            {
+                definition._sharedState.Invalidate();
+            }
+            else
+            {
+                GridUnitType oldUnitType = ((GridLength)e.OldValue).GridUnitType;
+                GridUnitType newUnitType = ((GridLength)e.NewValue).GridUnitType;
+
+                if (oldUnitType != newUnitType)
+                {
+                    definition.Parent.Invalidate();
+                }
+                else
+                {
+                    definition.Parent.InvalidateMeasure();
+                }
+            }
+        }
+
         /// <summary>
         /// Returns <c>true</c> if this definition is a part of shared group.
         /// </summary>

+ 3 - 1
src/Avalonia.Controls/RowDefinition.cs

@@ -31,7 +31,9 @@ namespace Avalonia.Controls
         /// </summary>
         static RowDefinition()
         {
-            AffectsParentMeasure(HeightProperty, MaxHeightProperty, MinHeightProperty);
+            AffectsParentMeasure(MaxHeightProperty, MinHeightProperty);
+
+            HeightProperty.Changed.AddClassHandler<DefinitionBase>(OnUserSizePropertyChanged);
         }
 
         /// <summary>

+ 9 - 9
tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs

@@ -16,7 +16,7 @@ namespace Avalonia.Controls.UnitTests
         public void Should_Set_ExitCode_After_Shutdown()
         {
             using (UnitTestApplication.Start(TestServices.MockThreadingInterface))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))    
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())    
             {
                 lifetime.Shutdown(1337);
 
@@ -31,7 +31,7 @@ namespace Avalonia.Controls.UnitTests
         public void Should_Close_All_Remaining_Open_Windows_After_Explicit_Exit_Call()
         {
             using (UnitTestApplication.Start(TestServices.StyledWindow))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 var windows = new List<Window> { new Window(), new Window(), new Window(), new Window() };
 
@@ -50,7 +50,7 @@ namespace Avalonia.Controls.UnitTests
         public void Should_Only_Exit_On_Explicit_Exit()
         {
             using (UnitTestApplication.Start(TestServices.StyledWindow))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 lifetime.ShutdownMode = ShutdownMode.OnExplicitShutdown;
 
@@ -84,7 +84,7 @@ namespace Avalonia.Controls.UnitTests
         public void Should_Exit_After_MainWindow_Closed()
         {
             using (UnitTestApplication.Start(TestServices.StyledWindow))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 lifetime.ShutdownMode = ShutdownMode.OnMainWindowClose;
 
@@ -112,7 +112,7 @@ namespace Avalonia.Controls.UnitTests
         public void Should_Exit_After_Last_Window_Closed()
         {
             using (UnitTestApplication.Start(TestServices.StyledWindow))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 lifetime.ShutdownMode = ShutdownMode.OnLastWindowClose;
 
@@ -142,7 +142,7 @@ namespace Avalonia.Controls.UnitTests
         public void Show_Should_Add_Window_To_OpenWindows()
         {
             using (UnitTestApplication.Start(TestServices.StyledWindow))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 var window = new Window();
 
@@ -156,7 +156,7 @@ namespace Avalonia.Controls.UnitTests
         public void Window_Should_Be_Added_To_OpenWindows_Only_Once()
         {
             using (UnitTestApplication.Start(TestServices.StyledWindow))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 var window = new Window();
 
@@ -174,7 +174,7 @@ namespace Avalonia.Controls.UnitTests
         public void Close_Should_Remove_Window_From_OpenWindows()
         {
             using (UnitTestApplication.Start(TestServices.StyledWindow))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 var window = new Window();
 
@@ -197,7 +197,7 @@ namespace Avalonia.Controls.UnitTests
                 windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object));
 
             using (UnitTestApplication.Start(services))
-            using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 var window = new Window();
 

+ 35 - 0
tests/Avalonia.Controls.UnitTests/GridTests.cs

@@ -1172,6 +1172,41 @@ namespace Avalonia.Controls.UnitTests
             Assert.Equal(0, grids[0].ColumnDefinitions[0].ActualWidth);
         }
 
+        [Fact]
+        public void Size_Group_Definition_Resizes_Are_Tracked()
+        {
+            var grids = new[] {
+                CreateGrid(("A", new GridLength(5, GridUnitType.Pixel)), (null, new GridLength())),
+                CreateGrid(("A", new GridLength(5, GridUnitType.Pixel)), (null, new GridLength())) };
+            var scope = new Grid();
+            foreach (var xgrids in grids)
+                scope.Children.Add(xgrids);
+
+            var root = new Grid();
+            root.UseLayoutRounding = false;
+            root.SetValue(Grid.IsSharedSizeScopeProperty, true);
+            root.Children.Add(scope);
+
+            root.Measure(new Size(50, 50));
+            root.Arrange(new Rect(new Point(), new Point(50, 50)));
+
+            PrintColumnDefinitions(grids[0]);
+            Assert.Equal(5, grids[0].ColumnDefinitions[0].ActualWidth);
+            Assert.Equal(5, grids[1].ColumnDefinitions[0].ActualWidth);
+
+            grids[0].ColumnDefinitions[0].Width = new GridLength(10, GridUnitType.Pixel);
+
+            foreach (Grid grid in grids)
+            {
+                grid.Measure(new Size(50, 50));
+                grid.Arrange(new Rect(new Point(), new Point(50, 50)));
+            }
+
+            PrintColumnDefinitions(grids[0]);
+            Assert.Equal(10, grids[0].ColumnDefinitions[0].ActualWidth);
+            Assert.Equal(10, grids[1].ColumnDefinitions[0].ActualWidth);
+        }
+
         [Fact]
         public void Collection_Changes_Are_Tracked()
         {

+ 3 - 3
tests/Avalonia.ReactiveUI.UnitTests/AutoSuspendHelperTest.cs

@@ -45,7 +45,7 @@ namespace Avalonia.ReactiveUI.UnitTests
         public void AutoSuspendHelper_Should_Immediately_Fire_IsLaunchingNew() 
         {
             using (UnitTestApplication.Start(TestServices.MockWindowingPlatform)) 
-            using (var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
+            using (var lifetime = new ClassicDesktopStyleApplicationLifetime())
             {
                 var isLaunchingReceived = false;
                 var application = AvaloniaLocator.Current.GetService<Application>();
@@ -86,7 +86,7 @@ namespace Avalonia.ReactiveUI.UnitTests
         public void ShouldPersistState_Should_Fire_On_App_Exit_When_SuspensionDriver_Is_Initialized() 
         {
             using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
-            using (var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) 
+            using (var lifetime = new ClassicDesktopStyleApplicationLifetime()) 
             {
                 var shouldPersistReceived = false;
                 var application = AvaloniaLocator.Current.GetService<Application>();
@@ -105,4 +105,4 @@ namespace Avalonia.ReactiveUI.UnitTests
             }
         }
     }
-}
+}