Преглед на файлове

Merge branch 'master' of https://github.com/AvaloniaUI/Avalonia into wip-animations

Jumar Macato преди 7 години
родител
ревизия
62d814f7dc

+ 1 - 1
readme.md

@@ -35,7 +35,7 @@ https://ci.appveyor.com/project/AvaloniaUI/Avalonia/branch/master/artifacts
 
 ## Documentation
 
-As mentioned above, Avalonia is still in alpha and as such there's not much documentation yet. You can take a look at the [getting started page](http://avaloniaui.net/guides/quickstart) for an overview of how to get started but probably the best thing to do for now is to already know a little bit about WPF/Silverlight/UWP/XAML and ask questions in our [Gitter room](https://gitter.im/AvaloniaUI/Avalonia).
+As mentioned above, Avalonia is still in alpha and as such there's not much documentation yet. You can take a look at the [getting started page](http://avaloniaui.net/docs/quickstart/) for an overview of how to get started but probably the best thing to do for now is to already know a little bit about WPF/Silverlight/UWP/XAML and ask questions in our [Gitter room](https://gitter.im/AvaloniaUI/Avalonia).
 
 There's also a high-level [architecture document](http://avaloniaui.net/architecture/project-structure) that is currently a little bit out of date, and I've also started writing blog posts on Avalonia at http://grokys.github.io/.
 

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

@@ -43,7 +43,8 @@ namespace Avalonia.Controls
         /// </summary>
         static Border()
         {
-            AffectsRender(BackgroundProperty, BorderBrushProperty);
+            AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
+            AffectsMeasure(BorderThicknessProperty);
         }
 
         /// <summary>
@@ -114,7 +115,7 @@ namespace Avalonia.Controls
                 Child.Arrange(new Rect(finalSize).Deflate(padding));
             }
 
-            _borderRenderHelper.Update(finalSize, BorderThickness, CornerRadius);           
+            _borderRenderHelper.Update(finalSize, BorderThickness, CornerRadius);
 
             return finalSize;
         }

+ 1 - 1
src/Avalonia.Controls/Button.cs

@@ -245,7 +245,7 @@ namespace Avalonia.Controls
         {
             base.OnPointerReleased(e);
 
-            if (e.MouseButton == MouseButton.Left)
+            if (IsPressed && e.MouseButton == MouseButton.Left)
             {
                 e.Device.Capture(null);
                 IsPressed = false;

+ 1 - 0
src/Avalonia.Controls/DropDown.cs

@@ -164,6 +164,7 @@ namespace Avalonia.Controls
                 else
                 {
                     IsDropDownOpen = !IsDropDownOpen;
+                    e.Handled = true;
                 }
             }
             base.OnPointerPressed(e);

+ 4 - 2
src/Avalonia.Controls/Presenters/ContentPresenter.cs

@@ -89,6 +89,8 @@ namespace Avalonia.Controls.Presenters
         /// </summary>
         static ContentPresenter()
         {
+            AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
+            AffectsMeasure(BorderThicknessProperty);
             ContentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
             ContentTemplateProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
             TemplatedParentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.TemplatedParentChanged);
@@ -383,7 +385,7 @@ namespace Avalonia.Controls.Presenters
             {
                 size = size.WithWidth(Math.Min(size.Width, DesiredSize.Width - padding.Left - padding.Right));
             }
-            
+
             if (verticalContentAlignment != VerticalAlignment.Stretch)
             {
                 size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height - padding.Top - padding.Bottom));
@@ -425,7 +427,7 @@ namespace Avalonia.Controls.Presenters
                 originY = Math.Floor(originY * scale) / scale;
             }
 
-            Child.Arrange(new Rect(originX, originY, size.Width, size.Height));
+            Child.Arrange(new Rect(originX, originY, Math.Max(0, size.Width), Math.Max(0, size.Height)));
 
             return finalSize;
         }

+ 1 - 1
src/Avalonia.Diagnostics/ViewModels/DevToolsViewModel.cs

@@ -86,7 +86,7 @@ namespace Avalonia.Diagnostics.ViewModels
 
         private void UpdateFocusedControl()
         {
-            _focusedControl = KeyboardDevice.Instance.FocusedElement?.GetType().Name;
+            FocusedControl = KeyboardDevice.Instance.FocusedElement?.GetType().Name;
         }
     }
 }

+ 3 - 1
src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs

@@ -167,7 +167,9 @@ namespace Avalonia.Rendering.SceneGraph
                 using (context.PushPostTransform(m))
                 using (context.PushTransformContainer())
                 {
-                    var clipBounds = bounds.TransformToAABB(contextImpl.Transform).Intersect(clip);
+                    var clipBounds = clipToBounds ?
+                        bounds.TransformToAABB(contextImpl.Transform).Intersect(clip) :
+                        clip;
 
                     forceRecurse = forceRecurse ||
                         node.ClipBounds != clipBounds ||

+ 1 - 0
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs

@@ -43,6 +43,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
                 Mode = Mode,
                 Path = pathInfo.Path,
                 Priority = Priority,
+                Source = Source,
                 RelativeSource = pathInfo.RelativeSource ?? RelativeSource,
                 DefaultAnchor = new WeakReference(GetDefaultAnchor((ITypeDescriptorContext)serviceProvider))
             };

+ 22 - 0
tests/Avalonia.Controls.UnitTests/BorderTests.cs

@@ -20,5 +20,27 @@ namespace Avalonia.Controls.UnitTests
 
             Assert.Equal(new Size(20, 20), target.DesiredSize);
         }
+
+        [Fact]
+        public void Child_Should_Arrange_With_Zero_Height_Width_If_Padding_Greater_Than_Child_Size()
+        {
+            Border content;
+
+            var target = new Border
+            {
+                Padding = new Thickness(6),
+                MaxHeight = 12,
+                MaxWidth = 12,
+                Child = content = new Border
+                {
+                    Height = 0,
+                    Width = 0
+                }
+            };
+
+            target.Arrange(new Rect(0, 0, 100, 100));
+
+            Assert.Equal(new Rect(6, 6, 0, 0), content.Bounds);
+        }
     }
 }

+ 25 - 0
tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs

@@ -210,5 +210,30 @@ namespace Avalonia.Controls.UnitTests.Presenters
 
             Assert.Equal(new Rect(84, 0, 16, 16), content.Bounds);
         }
+
+        [Fact]
+        public void Child_Arrange_With_Zero_Height_When_Padding_Height_Greater_Than_Child_Height()
+        {
+            Border content;
+            var target = new ContentPresenter
+            {
+                Padding = new Thickness(32),
+                MaxHeight = 32,
+                MaxWidth = 32,
+                HorizontalContentAlignment = HorizontalAlignment.Center,
+                VerticalContentAlignment = VerticalAlignment.Center,
+                Content = content = new Border
+                {
+                    Height = 0,
+                    Width = 0,
+                },
+            };
+
+            target.UpdateChild();
+
+            target.Arrange(new Rect(0, 0, 100, 100));
+
+            Assert.Equal(new Rect(48, 48, 0, 0), content.Bounds);
+        }
     }
 }

+ 48 - 0
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

@@ -83,6 +83,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
                         Margin = new Thickness(10, 20, 30, 40),
                         Child = canvas = new Canvas
                         {
+                            ClipToBounds = true,
                             Background = Brushes.AliceBlue,
                         }
                     }
@@ -129,6 +130,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
                             (border = new Border
                             {
                                 Background = Brushes.AliceBlue,
+                                ClipToBounds = true,
                                 Width = 100,
                                 Height = 100,
                                 [Canvas.LeftProperty] = 50,
@@ -173,6 +175,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
                             (border = new Border
                             {
                                 Background = Brushes.AliceBlue,
+                                ClipToBounds = true,
                                 Width = 100,
                                 Height = 100,
                                 [Canvas.LeftProperty] = 50,
@@ -254,6 +257,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
                         Margin = new Thickness(24, 26),
                         Child = target = new Border
                         {
+                            ClipToBounds = true,
                             Margin = new Thickness(26, 24),
                             Width = 100,
                             Height = 100,
@@ -515,6 +519,50 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
             }
         }
 
+        [Fact]
+        public void Should_Update_ClipBounds_For_Negative_Margin()
+        {
+            using (TestApplication())
+            {
+                Decorator decorator;
+                Border border;
+                var tree = new TestRoot
+                {
+                    Width = 100,
+                    Height = 100,
+                    Child = decorator = new Decorator
+                    {
+                        Margin = new Thickness(0, 10, 0, 0),
+                        Child = border = new Border
+                        {
+                            Background = Brushes.Red,
+                            ClipToBounds = true,
+                            Margin = new Thickness(0, -5, 0, 0),
+                        }
+                    }
+                };
+
+                var layout = AvaloniaLocator.Current.GetService<ILayoutManager>();
+                layout.ExecuteInitialLayoutPass(tree);
+
+                var scene = new Scene(tree);
+                var sceneBuilder = new SceneBuilder();
+                sceneBuilder.UpdateAll(scene);
+
+                var borderNode = scene.FindNode(border);
+                Assert.Equal(new Rect(0, 5, 100, 95), borderNode.ClipBounds);
+
+                border.Margin = new Thickness(0, -8, 0, 0);
+                layout.ExecuteLayoutPass();
+
+                scene = scene.CloneScene();
+                sceneBuilder.Update(scene, border);
+
+                borderNode = scene.FindNode(border);
+                Assert.Equal(new Rect(0, 2, 100, 98), borderNode.ClipBounds);
+            }
+        }
+
         [Fact]
         public void Should_Update_Descendent_Tranform_When_Margin_Changed()
         {