Browse Source

Merge branch 'master' into fixes/1484-nested-autoclose-popups

pull/1489/head
ahopper 9 years ago
committed by GitHub
parent
commit
cf547b22d0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/Avalonia.Controls/Border.cs
  2. 2
      src/Avalonia.Controls/Button.cs
  3. 1
      src/Avalonia.Controls/DropDown.cs
  4. 6
      src/Avalonia.Controls/Presenters/ContentPresenter.cs
  5. 4
      src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
  6. 1
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs
  7. 22
      tests/Avalonia.Controls.UnitTests/BorderTests.cs
  8. 25
      tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs
  9. 48
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

5
src/Avalonia.Controls/Border.cs

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

2
src/Avalonia.Controls/Button.cs

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

1
src/Avalonia.Controls/DropDown.cs

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

6
src/Avalonia.Controls/Presenters/ContentPresenter.cs

@ -89,6 +89,8 @@ namespace Avalonia.Controls.Presenters
/// </summary> /// </summary>
static ContentPresenter() static ContentPresenter()
{ {
AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
AffectsMeasure(BorderThicknessProperty);
ContentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged); ContentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
ContentTemplateProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged); ContentTemplateProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
TemplatedParentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.TemplatedParentChanged); 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)); size = size.WithWidth(Math.Min(size.Width, DesiredSize.Width - padding.Left - padding.Right));
} }
if (verticalContentAlignment != VerticalAlignment.Stretch) if (verticalContentAlignment != VerticalAlignment.Stretch)
{ {
size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height - padding.Top - padding.Bottom)); 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; 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; return finalSize;
} }

4
src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs

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

1
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs

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

22
tests/Avalonia.Controls.UnitTests/BorderTests.cs

@ -20,5 +20,27 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(20, 20), target.DesiredSize); 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
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); 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
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), Margin = new Thickness(10, 20, 30, 40),
Child = canvas = new Canvas Child = canvas = new Canvas
{ {
ClipToBounds = true,
Background = Brushes.AliceBlue, Background = Brushes.AliceBlue,
} }
} }
@ -129,6 +130,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
(border = new Border (border = new Border
{ {
Background = Brushes.AliceBlue, Background = Brushes.AliceBlue,
ClipToBounds = true,
Width = 100, Width = 100,
Height = 100, Height = 100,
[Canvas.LeftProperty] = 50, [Canvas.LeftProperty] = 50,
@ -173,6 +175,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
(border = new Border (border = new Border
{ {
Background = Brushes.AliceBlue, Background = Brushes.AliceBlue,
ClipToBounds = true,
Width = 100, Width = 100,
Height = 100, Height = 100,
[Canvas.LeftProperty] = 50, [Canvas.LeftProperty] = 50,
@ -254,6 +257,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
Margin = new Thickness(24, 26), Margin = new Thickness(24, 26),
Child = target = new Border Child = target = new Border
{ {
ClipToBounds = true,
Margin = new Thickness(26, 24), Margin = new Thickness(26, 24),
Width = 100, Width = 100,
Height = 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] [Fact]
public void Should_Update_Descendent_Tranform_When_Margin_Changed() public void Should_Update_Descendent_Tranform_When_Margin_Changed()
{ {

Loading…
Cancel
Save