Browse Source

Merge pull request #1488 from AvaloniaUI/fixes/1436-border-layout-issues

Fix ZIndex / Layout issue with Styles and Border Control
pull/1498/head
danwalmsley 9 years ago
committed by GitHub
parent
commit
25f25dd1c4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Avalonia.Controls/Border.cs
  2. 2
      src/Avalonia.Controls/Presenters/ContentPresenter.cs
  3. 4
      src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
  4. 48
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

3
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>

2
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);

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 ||

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